Class Excel
This class adds static methods for work with excel documents.
Driver Type: Desktop
Note:
In order to work with Excel document, it should be opened with openExcel method first
- Samples
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");
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcloseExcel(String filePath) Close excel file and remove it from script context.static voiddeleteCell(String filePath, ExcelCellPosition position) Clear of value of cell.static voiddeleteCell(String filePath, String coordinate) Clear of value of cell.static StringgetActiveCell(String filePath) Get active cell.static StringgetCell(String filePath, ExcelCellPosition position) Get value of cell and return it as string.static StringGet value of cell and return it as string.getColumn(String filePath, ExcelColumnRowPosition position) Get column valuesgetColumn(String filePath, ExcelColumnRowPosition position, Integer rowFrom, Integer rowTo) Get column valuesGet column valuesGet column valuesGet values of the range.Get values of the range.Get row valuesGet row valuesgetRow(String filePath, ExcelColumnRowPosition position) Get row valuesgetRow(String filePath, ExcelColumnRowPosition position, String columnFrom, String columnTo) Get row valuesstatic voidRead excel file by path, store this in script context.static voidSave excel file.static voidSave excel as new file.static voidsetActiveCell(String filePath, ExcelCellPosition position) Set active cell.static voidsetActiveCell(String filePath, String coordinate) Set active cell.static voidsetCell(String filePath, ExcelCellPosition position, String value) Set value of cell.static voidsetCell(String filePath, ExcelCellPosition position, BigDecimal value) Set value of cell.static voidSet value of cell.static voidsetCell(String filePath, String coordinate, BigDecimal value) Set value of cell.static voidSet value of cell.static voidGet values of the rangestatic voidGet values of the rangestatic voidswitchSheet(String filePath, int index) Select as active sheet by index.static voidswitchSheet(String filePath, String name) Select as active sheet by index.
-
Method Details
-
openExcel
Read excel file by path, store this in script context.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)
- Throws:
IOException
-
closeExcel
Close excel file and remove it from script context.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)closeExcel(filePath)
- Throws:
IOException
-
saveExcel
Save excel file.
- Parameters:
filePath- string representation of path to excel file.- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)saveExcel(filePath)
- Throws:
IOException
-
saveExcel
Save excel as new file.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.newFilePath- string representation of new path to excel file- Example
def filePath = 'D://temp//excel.xlsx'def newFilePath = 'D://temp//new-excel.xlsx'openExcel(filePath)saveExcel(filePath, newFilePath)
- Throws:
IOException
-
switchSheet
Select as active sheet by index.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.index- index of sheet in excel file. Starts from 0- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)switchSheet(filePath, 1)
-
switchSheet
Select as active sheet by index.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.name- name of sheet in excel file.- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)switchSheet(filePath, 'Names')
-
getCell
Get value of cell and return it as string.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelCellPosition.- Returns:
- string representation of value of cell.
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)def cellValue = getCell(filePath, ExcelCellPosition.CURRENT)
- See Also:
-
getCell
Get value of cell and return it as string.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.coordinate- string representation coordinate of cell (A1).- Returns:
- string representation of value of cell.
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)def cellValue = getCell(filePath, 'B1')
-
setCell
Set value of cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelCellPosition.value- string representation of value of cell- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, ExcelCellPosition.CURRENT, 'New Value')
- See Also:
-
setCell
Set value of cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.coordinate- string representation coordinate of cell (A1).value- string representation of value of cell- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, 'B1', 'New Value')
-
setCell
Set value of cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelCellPosition.value-BigDecimalvalue to be set to cell- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, ExcelCellPosition.CURRENT, new BigDecimal('3.14'))
- See Also:
-
setCell
Set value of cell.
Note: implemented for desktop driver only
- Parameters:
filePath- string representation of path to excel file.coordinate- string representation coordinate of cell (A1).value-BigDecimalvalue to be set to cell- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setCell(filePath, 'B1', new BigDecimal('3.14'))
-
setCells
public static void setCells(String filePath, String coordinate, List<String> values, boolean isVertical) Set value of cell.
Note: implemented for desktop driver only
- Parameters:
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)- Example
def filePath = 'D://temp//excel.xlsx'List values = ['val1','val2','val3','val4']openExcel(filePath)setCells(filePath, 'C3', values, false)
-
getRow
Get row values
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelColumnRowPosition.- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, ExcelColumnRowPosition.FIRST)
- See Also:
-
getRow
public static List<String> getRow(String filePath, ExcelColumnRowPosition position, String columnFrom, String columnTo) Get row values
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelColumnRowPosition.columnFrom- string representation of start column lettercolumnTo- string representation of end column letter- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, ExcelColumnRowPosition.FIRST, 'A', 'D')
- See Also:
-
getRow
Get row values
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.rowNum- int number of row.- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, 10)
-
getRow
Get row values
Driver Type: Desktop
- Parameters:
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 letter- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rowValues = getRow(filePath, 10, 'A', 'D')
-
getColumn
Get column values
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, ExcelColumnRowPosition.LAST)
- See Also:
-
getColumn
public static List<String> getColumn(String filePath, ExcelColumnRowPosition position, Integer rowFrom, Integer rowTo) Get column values
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelColumnRowPosition.rowFrom- integer representation of start row numberrowTo- integer representation of end row number- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, ExcelColumnRowPosition.LAST, 2, 4)
- See Also:
-
getColumn
Get column values
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.columnLetters- string representation of column letters.- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, 'C')
- See Also:
-
getColumn
public static List<String> getColumn(String filePath, String columnLetters, Integer rowFrom, Integer rowTo) Get column values
Driver Type: Desktop
- Parameters:
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 number- Returns:
- list of values
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List columnValues = getColumn(filePath, 'C', 2, 4)
-
deleteCell
Clear of value of cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelCellPosition.- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)deleteCell(filePath, ExcelCellPosition.CURRENT)
- See Also:
-
deleteCell
Clear of value of cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.coordinate- string representation coordinate of cell (A1).- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)deleteCell(filePath, 'A1')
-
setActiveCell
Set active cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.coordinate- string representation coordinate of cell (A1).- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setActiveCell(filePath, 'A1')
-
setActiveCell
Set active cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.position- ExcelCellPosition.- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)setActiveCell(filePath, ExcelCellPosition.CURRENT)
- See Also:
-
getActiveCell
Get active cell.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.- Returns:
- string that represent of coordinate
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)def activeCell = getActiveCell(filePath)
-
getRange
public static List<List<String>> getRange(String filePath, String coordinateFrom, String coordinateTo) Get values of the range.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.coordinateFrom- coordinate where range startscoordinateTo- coordinate where range ends- Returns:
- list of list of strings that represents range of cells
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rangeValues = getRange(filePath, 'F1', 'H3')
-
getRange
Get values of the range.
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.coordinateFrom- coordinate where range starts- Returns:
- list of list of strings that represents range of cells
- Example
def filePath = 'D://temp//excel.xlsx'openExcel(filePath)List rangeValues = getRange(filePath, 'A4')
-
setRange
public static void setRange(String filePath, String coordinateFrom, String coordinateTo, List<List<String>> values) Get values of the range
Driver Type: Desktop
- Parameters:
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- Example
def filePath = 'D://temp//excel.xlsx'List values = [['val1','val2','val3','val4']]openExcel(filePath)setRange(filePath, 'J10', 'K12', values)
-
setRange
Get values of the range
Driver Type: Desktop
- Parameters:
filePath- string representation of path to excel file.coordinateFrom- coordinate where range startsvalues- list of lists of strings that represents values of the cells- Example
def filePath = 'D://temp//excel.xlsx'List values = [['val1','val2','val3','val4']]openExcel(filePath)setRange(filePath, 'B2', values)
-