public class Excel
extends java.lang.Object
Driver Type: Desktop
In order to work with Excel document, it should be opened with openExcel method first
openExcel("path/to/excel/file");switchSheet("path/to/excel/file", index);setCell("path/to/excel/file", row, column, value);saveExcel("path/to/excel/file");closeExcel("path/to/excel/file");| Modifier and Type | Method and Description |
|---|---|
static void |
closeExcel(java.lang.String filePath)
Close excel file and remove it from script context.
|
static void |
deleteCell(java.lang.String filePath,
ExcelCellPosition position)
Clear of value of cell.
|
static void |
deleteCell(java.lang.String filePath,
java.lang.String coordinate)
Clear of value of cell.
|
static java.lang.String |
getActiveCell(java.lang.String filePath)
Get active cell.
|
static java.lang.String |
getCell(java.lang.String filePath,
ExcelCellPosition position)
Get value of cell and return it as string.
|
static java.lang.String |
getCell(java.lang.String filePath,
java.lang.String coordinate)
Get value of cell and return it as string.
|
static java.util.List<java.lang.String> |
getColumn(java.lang.String filePath,
ExcelColumnRowPosition position)
Get column values
|
static java.util.List<java.lang.String> |
getColumn(java.lang.String filePath,
ExcelColumnRowPosition position,
java.lang.Integer rowFrom,
java.lang.Integer rowTo)
Get column values
|
static java.util.List<java.lang.String> |
getColumn(java.lang.String filePath,
java.lang.String columnLetters)
Get column values
|
static java.util.List<java.lang.String> |
getColumn(java.lang.String filePath,
java.lang.String columnLetters,
java.lang.Integer rowFrom,
java.lang.Integer rowTo)
Get column values
|
static java.util.List<java.util.List<java.lang.String>> |
getRange(java.lang.String filePath,
java.lang.String coordinateFrom)
Get values of the range.
|
static java.util.List<java.util.List<java.lang.String>> |
getRange(java.lang.String filePath,
java.lang.String coordinateFrom,
java.lang.String coordinateTo)
Get values of the range.
|
static java.util.List<java.lang.String> |
getRow(java.lang.String filePath,
ExcelColumnRowPosition position)
Get row values
|
static java.util.List<java.lang.String> |
getRow(java.lang.String filePath,
ExcelColumnRowPosition position,
java.lang.String columnFrom,
java.lang.String columnTo)
Get row values
|
static java.util.List<java.lang.String> |
getRow(java.lang.String filePath,
int rowNum)
Get row values
|
static java.util.List<java.lang.String> |
getRow(java.lang.String filePath,
int rowNum,
java.lang.String columnFrom,
java.lang.String columnTo)
Get row values
|
static void |
openExcel(java.lang.String filePath)
Read excel file by path, store this in script context.
|
static void |
saveExcel(java.lang.String filePath)
Save excel file.
|
static void |
saveExcel(java.lang.String filePath,
java.lang.String newFilePath)
Save excel as new file.
|
static void |
setActiveCell(java.lang.String filePath,
ExcelCellPosition position)
Set active cell.
|
static void |
setActiveCell(java.lang.String filePath,
java.lang.String coordinate)
Set active cell.
|
static void |
setCell(java.lang.String filePath,
ExcelCellPosition position,
java.math.BigDecimal value)
Set value of cell.
|
static void |
setCell(java.lang.String filePath,
ExcelCellPosition position,
java.lang.String value)
Set value of cell.
|
static void |
setCell(java.lang.String filePath,
java.lang.String coordinate,
java.math.BigDecimal value)
Set value of cell.
|
static void |
setCell(java.lang.String filePath,
java.lang.String coordinate,
java.lang.String value)
Set value of cell.
|
static void |
setCells(java.lang.String filePath,
java.lang.String coordinate,
java.util.List<java.lang.String> values,
boolean isVertical)
Set value of cell.
|
static void |
setRange(java.lang.String filePath,
java.lang.String coordinateFrom,
java.util.List<java.util.List<java.lang.String>> values)
Get values of the range
|
static void |
setRange(java.lang.String filePath,
java.lang.String coordinateFrom,
java.lang.String coordinateTo,
java.util.List<java.util.List<java.lang.String>> values)
Get values of the range
|
static void |
switchSheet(java.lang.String filePath,
int index)
Select as active sheet by index.
|
static void |
switchSheet(java.lang.String filePath,
java.lang.String name)
Select as active sheet by index.
|
public static void openExcel(java.lang.String filePath)
Read excel file by path, store this in script context.
Driver Type: Desktop
filePath - string representation of path to excel file.
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)public static void closeExcel(java.lang.String filePath)
Close excel file and remove it from script context.
Driver Type: Desktop
filePath - string representation of path to excel file.
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)closeExcel(filePath)public static void saveExcel(java.lang.String filePath)
Save excel file.
filePath - string representation of path to excel file.
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)saveExcel(filePath)public static void saveExcel(java.lang.String filePath,
java.lang.String newFilePath)
Save excel as new file.
Driver Type: Desktop
filePath - string representation of path to excel file.newFilePath - string representation of new path to excel file
def filePath = 'D://temp//excel.xlsx'def newFilePath = 'D://temp//new-excel.xlsx'openExcel(filePath)saveExcel(filePath, newFilePath)public static void switchSheet(java.lang.String filePath,
int index)
Select as active sheet by index.
Driver Type: Desktop
filePath - string representation of path to excel file.index - index of sheet in excel file. Starts from 0
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)switchSheet(filePath, 1)public static void switchSheet(java.lang.String filePath,
java.lang.String name)
Select as active sheet by index.
Driver Type: Desktop
filePath - string representation of path to excel file.name - name of sheet in excel file.
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)switchSheet(filePath, 'Names')public static java.lang.String getCell(java.lang.String filePath,
ExcelCellPosition position)
Get value of cell and return it as string.
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelCellPosition.def filePath = 'D://temp//excel.xlsx'openExcel(filePath)def cellValue = getCell(filePath, ExcelCellPosition.CURRENT)ExcelCellPositionpublic static java.lang.String getCell(java.lang.String filePath,
java.lang.String coordinate)
Get value of cell and return it as string.
Driver Type: Desktop
filePath - string representation of path to excel file.coordinate - string representation coordinate of cell (A1).def filePath = 'D://temp//excel.xlsx'openExcel(filePath)def cellValue = getCell(filePath, 'B1')public static void setCell(java.lang.String filePath,
ExcelCellPosition position,
java.lang.String value)
Set value of cell.
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelCellPosition.value - string representation of value of cell
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, ExcelCellPosition.CURRENT, 'New Value')ExcelCellPositionpublic static void setCell(java.lang.String filePath,
java.lang.String coordinate,
java.lang.String value)
Set value of cell.
Driver Type: Desktop
filePath - string representation of path to excel file.coordinate - string representation coordinate of cell (A1).value - string representation of value of cell
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, 'B1', 'New Value')public static void setCell(java.lang.String filePath,
ExcelCellPosition position,
java.math.BigDecimal value)
Set value of cell.
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelCellPosition.value - BigDecimal value to be set to cell
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, ExcelCellPosition.CURRENT, new BigDecimal('3.14'))ExcelCellPositionpublic static void setCell(java.lang.String filePath,
java.lang.String coordinate,
java.math.BigDecimal value)
Set value of cell.
Note: implemented for desktop driver only
filePath - string representation of path to excel file.coordinate - string representation coordinate of cell (A1).value - BigDecimal value to be set to cell
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, 'B1', new BigDecimal('3.14'))public static void setCells(java.lang.String filePath,
java.lang.String coordinate,
java.util.List<java.lang.String> values,
boolean isVertical)
Set value of cell.
Note: implemented for desktop driver only
filePath - string representation of path to excel file.coordinate - string representation coordinate of cell (A1).values - list of string representation of values of cellsisVertical - boolean representation od direction (true is vertical direction)
def filePath = 'D://temp//excel.xlsx'List values = ['val1','val2','val3','val4']openExcel(filePath)setCells(filePath, 'C3', values, false)public static java.util.List<java.lang.String> getRow(java.lang.String filePath,
ExcelColumnRowPosition position)
Get row values
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelColumnRowPosition.def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, ExcelColumnRowPosition.FIRST)ExcelColumnRowPositionpublic static java.util.List<java.lang.String> getRow(java.lang.String filePath,
ExcelColumnRowPosition position,
java.lang.String columnFrom,
java.lang.String columnTo)
Get row values
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelColumnRowPosition.columnFrom - string representation of start column lettercolumnTo - string representation of end column letterdef filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, ExcelColumnRowPosition.FIRST, 'A', 'D')ExcelColumnRowPositionpublic static java.util.List<java.lang.String> getRow(java.lang.String filePath,
int rowNum)
Get row values
Driver Type: Desktop
filePath - string representation of path to excel file.rowNum - int number of row.def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, 10)public static java.util.List<java.lang.String> getRow(java.lang.String filePath,
int rowNum,
java.lang.String columnFrom,
java.lang.String columnTo)
Get row values
Driver Type: Desktop
filePath - string representation of path to excel file.rowNum - int number of row.columnFrom - string representation of start column lettercolumnTo - string representation of end column letterdef filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, 10, 'A', 'D')public static java.util.List<java.lang.String> getColumn(java.lang.String filePath,
ExcelColumnRowPosition position)
Get column values
Driver Type: Desktop
filePath - string representation of path to excel file.def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, ExcelColumnRowPosition.LAST)ExcelColumnRowPositionpublic static java.util.List<java.lang.String> getColumn(java.lang.String filePath,
ExcelColumnRowPosition position,
java.lang.Integer rowFrom,
java.lang.Integer rowTo)
Get column values
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelColumnRowPosition.rowFrom - integer representation of start row numberrowTo - integer representation of end row numberdef filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, ExcelColumnRowPosition.LAST, 2, 4)ExcelColumnRowPositionpublic static java.util.List<java.lang.String> getColumn(java.lang.String filePath,
java.lang.String columnLetters)
Get column values
Driver Type: Desktop
filePath - string representation of path to excel file.columnLetters - string representation of column letters.def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, 'C')ExcelColumnRowPositionpublic static java.util.List<java.lang.String> getColumn(java.lang.String filePath,
java.lang.String columnLetters,
java.lang.Integer rowFrom,
java.lang.Integer rowTo)
Get column values
Driver Type: Desktop
filePath - string representation of path to excel file.columnLetters - string representation of column letters.rowFrom - integer representation of start row numberrowTo - integer representation of end row numberdef filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, 'C', 2, 4)public static void deleteCell(java.lang.String filePath,
ExcelCellPosition position)
Clear of value of cell.
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelCellPosition.
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)deleteCell(filePath, ExcelCellPosition.CURRENT)ExcelCellPositionpublic static void deleteCell(java.lang.String filePath,
java.lang.String coordinate)
Clear of value of cell.
Driver Type: Desktop
filePath - string representation of path to excel file.coordinate - string representation coordinate of cell (A1).
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)deleteCell(filePath, 'A1')public static void setActiveCell(java.lang.String filePath,
java.lang.String coordinate)
Set active cell.
Driver Type: Desktop
filePath - string representation of path to excel file.coordinate - string representation coordinate of cell (A1).
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setActiveCell(filePath, 'A1')public static void setActiveCell(java.lang.String filePath,
ExcelCellPosition position)
Set active cell.
Driver Type: Desktop
filePath - string representation of path to excel file.position - ExcelCellPosition.
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setActiveCell(filePath, ExcelCellPosition.CURRENT)ExcelCellPositionpublic static java.lang.String getActiveCell(java.lang.String filePath)
Get active cell.
Driver Type: Desktop
filePath - string representation of path to excel file.def filePath = 'D://temp//excel.xlsx'openExcel(filePath)def activeCell = getActiveCell(filePath)public static java.util.List<java.util.List<java.lang.String>> getRange(java.lang.String filePath,
java.lang.String coordinateFrom,
java.lang.String coordinateTo)
Get values of the range.
Driver Type: Desktop
filePath - string representation of path to excel file.coordinateFrom - coordinate where range startscoordinateTo - coordinate where range endsdef filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rangeValues = getRange(filePath, 'F1', 'H3')public static java.util.List<java.util.List<java.lang.String>> getRange(java.lang.String filePath,
java.lang.String coordinateFrom)
Get values of the range.
Driver Type: Desktop
filePath - string representation of path to excel file.coordinateFrom - coordinate where range startsdef filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rangeValues = getRange(filePath, 'A4')public static void setRange(java.lang.String filePath,
java.lang.String coordinateFrom,
java.lang.String coordinateTo,
java.util.List<java.util.List<java.lang.String>> values)
Get values of the range
Driver Type: Desktop
filePath - string representation of path to excel file.coordinateFrom - coordinate where range startscoordinateTo - coordinate where range endsvalues - list of lists of strings that represents values of the cells
def filePath = 'D://temp//excel.xlsx'List values = [['val1','val2','val3','val4']]openExcel(filePath)setRange(filePath, 'J10', 'K12', values)public static void setRange(java.lang.String filePath,
java.lang.String coordinateFrom,
java.util.List<java.util.List<java.lang.String>> values)
Get values of the range
Driver Type: Desktop
filePath - string representation of path to excel file.coordinateFrom - coordinate where range startsvalues - list of lists of strings that represents values of the cells
def filePath = 'D://temp//excel.xlsx'List values = [['val1','val2','val3','val4']]openExcel(filePath)setRange(filePath, 'B2', values)Copyright © 2024 WorkFusion, Inc. All rights reserved.