public class Excel extends 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(String filePath)
Close excel file and remove it from script context.
|
static void |
deleteCell(String filePath,
ExcelCellPosition position)
Clear of value of cell.
|
static void |
deleteCell(String filePath,
String coordinate)
Clear of value of cell.
|
static String |
getActiveCell(String filePath)
Get active cell.
|
static String |
getCell(String filePath,
ExcelCellPosition position)
Get value of cell and return it as string.
|
static String |
getCell(String filePath,
String coordinate)
Get value of cell and return it as string.
|
static List<String> |
getColumn(String filePath,
ExcelColumnRowPosition position)
Get column values
|
static List<String> |
getColumn(String filePath,
ExcelColumnRowPosition position,
Integer rowFrom,
Integer rowTo)
Get column values
|
static List<String> |
getColumn(String filePath,
String columnLetters)
Get column values
|
static List<String> |
getColumn(String filePath,
String columnLetters,
Integer rowFrom,
Integer rowTo)
Get column values
|
static List<List<String>> |
getRange(String filePath,
String coordinateFrom)
Get values of the range.
|
static List<List<String>> |
getRange(String filePath,
String coordinateFrom,
String coordinateTo)
Get values of the range.
|
static List<String> |
getRow(String filePath,
ExcelColumnRowPosition position)
Get row values
|
static List<String> |
getRow(String filePath,
ExcelColumnRowPosition position,
String columnFrom,
String columnTo)
Get row values
|
static List<String> |
getRow(String filePath,
int rowNum)
Get row values
|
static List<String> |
getRow(String filePath,
int rowNum,
String columnFrom,
String columnTo)
Get row values
|
static void |
openExcel(String filePath)
Read excel file by path, store this in script context.
|
static void |
saveExcel(String filePath)
Save excel file.
|
static void |
saveExcel(String filePath,
String newFilePath)
Save excel as new file.
|
static void |
setActiveCell(String filePath,
ExcelCellPosition position)
Set active cell.
|
static void |
setActiveCell(String filePath,
String coordinate)
Set active cell.
|
static void |
setCell(String filePath,
ExcelCellPosition position,
BigDecimal value)
Set value of cell.
|
static void |
setCell(String filePath,
ExcelCellPosition position,
String value)
Set value of cell.
|
static void |
setCell(String filePath,
String coordinate,
BigDecimal value)
Set value of cell.
|
static void |
setCell(String filePath,
String coordinate,
String value)
Set value of cell.
|
static void |
setCells(String filePath,
String coordinate,
List<String> values,
boolean isVertical)
Set value of cell.
|
static void |
setRange(String filePath,
String coordinateFrom,
List<List<String>> values)
Get values of the range
|
static void |
setRange(String filePath,
String coordinateFrom,
String coordinateTo,
List<List<String>> values)
Get values of the range
|
static void |
switchSheet(String filePath,
int index)
Select as active sheet by index.
|
static void |
switchSheet(String filePath,
String name)
Select as active sheet by index.
|
public static void openExcel(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(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(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(String filePath, 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(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(String filePath, 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 String getCell(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 String getCell(String filePath, 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(String filePath, ExcelCellPosition position, 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(String filePath, String coordinate, 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(String filePath, ExcelCellPosition position, 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(String filePath, String coordinate, 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(String filePath, String coordinate, List<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 List<String> getRow(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 List<String> getRow(String filePath, ExcelColumnRowPosition position, String columnFrom, 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 List<String> getRow(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 List<String> getRow(String filePath, int rowNum, String columnFrom, 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 List<String> getColumn(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 List<String> getColumn(String filePath, ExcelColumnRowPosition position, Integer rowFrom, 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 List<String> getColumn(String filePath, 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 List<String> getColumn(String filePath, String columnLetters, Integer rowFrom, 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(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(String filePath, 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(String filePath, 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(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 String getActiveCell(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 List<List<String>> getRange(String filePath, String coordinateFrom, 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 List<List<String>> getRange(String filePath, 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(String filePath, String coordinateFrom, String coordinateTo, List<List<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(String filePath, String coordinateFrom, List<List<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 2016, WorkFusion, Inc.