- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- setFileName
- readFile
- isLoaded
- close
- getCellType
- getCellType
- getCellBooleanValue
- getCellNumericValue
- getCellStringValue
- getCellFormula
- getCellErrorValue
- getCellDateValue
- getWorkbook
- getCellBooleanValue
- getCellNumericValue
- getCellStringValue
- getCellFormula
- getCellErrorValue
- getCellDateValue
- getCellType
- getCellBooleanValue
- getCellNumericValue
- getCellStringValue
- getCellFormula
- getCellErrorValue
- getCellDateValue
- getNumberOfSheets
- getLastRowNum
- getLastRowNum
- getFirstRowNum
- getFirstRowNum
- getFirstCellNum
- getFirstCellNum
- getLastCellNum
- getLastCellNum
- cellExists
- cellExists
- cellExists
- clearCell
- readTableFunction
- readTableFunction
- readTableFunction
- getCellFormulaType
- getCellFormulaType
- getCellFormulaType
- getSheetName
- getSheetIndex
- readHyperArray
- readHyperArray
- readHyperArray
- writeFile
- writeFile
- setChanged
- createCell
- createCell
- createCell
- setCellValue
- setCellValue
- setCellValue
- setCellValue
- setCellFormula
- setCellValue
- setCellValue
- setCellValue
- setCellValue
- setCellFormula
- setCellValue
- setCellValue
- setCellValue
- setCellValue
- setCellFormula
- toString
- writeDataSet
- writeDataSet
- writeDataSet
- evaluateFormulas
- java.lang.Object
- com.anylogic.engine.connectivity.ExcelFile
- All Implemented Interfaces:
Serializable
public class ExcelFile extends Object implements Serializable
This class is a representation of a workbook.
File access
This class have 2 methods for the file access: readFile()
and
writeFile()
. Also it has ability loading another file or saving to
other location - see setFileName(String)
.
Data access
Data may be read from and written to a workbook using various
getCell*(...)
and setCell*(...)
methods. This
object allows reading table functions (readTableFunction()
) and
hyper arrays (with 1 or 2 dimensions, see readHyperArray
) from
the sheet. Also, data sets may be written using writeDataSet
.
New cells may need to be created before writing data:
createCell(...)
(cell may be checked using
cellExists()
)
Cell access
All cell-access methods have 3 forms of cell location specification:
- 3 numbers (one-based): sheet index, row index, column index
- sheet name and 2 (one-based) numbers row index and column index
- cell name in the following format:
<sheet name>!<column name><row number>
The sheet name can be skipped, then the first sheet is assumed.
Examples (without quotes):
"Sheet1!A3"
,"Sheet2!AAB100"
,"B2"
Model Snapshot serialization notes
This workbook may include all unsaved data (if any) to the model snapshot -
this is controlled by parameter saveToSnapshot
of
constructor.
- Author:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
- Serialized Form
Modifier and Type | Field | Description |
---|---|---|
static final org.apache.poi.ss.usermodel.CellType | CELL_TYPE_BLANK |
Blank Cell type
|
static final org.apache.poi.ss.usermodel.CellType | CELL_TYPE_BOOLEAN |
Boolean Cell type
|
static final org.apache.poi.ss.usermodel.CellType | CELL_TYPE_ERROR |
Error Cell type
|
static final org.apache.poi.ss.usermodel.CellType | CELL_TYPE_FORMULA |
Formula Cell type
|
static final org.apache.poi.ss.usermodel.CellType | CELL_TYPE_NUMERIC |
Numeric Cell type
|
static final org.apache.poi.ss.usermodel.CellType | CELL_TYPE_STRING |
String Cell type
|
Constructor | Description |
---|---|
ExcelFile |
Creates new ExcelTM file accessor
|
ExcelFile |
Deprecated.
this constructor is obsolete and will be removed in future
|
Modifier and Type | Method | Description |
---|---|---|
boolean | cellExists |
Returns
true if the cell at the given position exists in the
workbook |
boolean | cellExists |
Returns
true if the cell at the given position exists in the
workbook |
boolean | cellExists |
Returns
true if the cell at the given position exists in the
workbook |
void | clearCell |
Clears type and value of the cell.
|
void | close() |
Closes the workbook.
|
void | createCell |
Creates new cell at the given position.
|
void | createCell |
Creates new cell at the given position.
|
void | createCell |
Creates new cell at the given position.
|
void | evaluateFormulas() |
Evaluates formulas and saves the results for all the cells containing
formulas in this workbook.
The cells are left as formula cells. |
boolean | getCellBooleanValue |
Returns the value of the cell as a
boolean .For strings, numbers, and errors, throws an exception. For blank cells returns false . |
boolean | getCellBooleanValue |
Returns the value of the cell as a
boolean .For strings, numbers, and errors, throws an exception. For blank cells returns false . |
boolean | getCellBooleanValue |
Returns the value of the cell as a
boolean .For strings, numbers, and errors, throws an exception. For blank cells returns false . |
Date | getCellDateValue |
Returns the value of the cell as a date.
For strings throws an exception. For blank cells returns null . |
Date | getCellDateValue |
Returns the value of the cell as a date.
For strings throws an exception. For blank cells returns null . |
Date | getCellDateValue |
Returns the value of the cell as a date.
For strings throws an exception. For blank cells returns null . |
byte | getCellErrorValue |
Returns the value of the cell as an error code.
For strings, numbers, and booleans, throws an exception. For blank cells returns a 0 . |
byte | getCellErrorValue |
Returns the value of the cell as an error code.
For strings, numbers, and booleans, throws an exception. For blank cells returns a 0 . |
byte | getCellErrorValue |
Returns the value of the cell as an error code.
For strings, numbers, and booleans, throws an exception. For blank cells returns a 0 . |
String | getCellFormula |
Return a formula for the cell, for example, SUM(C4:E4)
|
String | getCellFormula |
Return a formula for the cell, for example, SUM(C4:E4)
|
String | getCellFormula |
Return a formula for the cell, for example, SUM(C4:E4)
|
org.apache.poi.ss.usermodel.CellType | getCellFormulaType |
Returns the type of the formula cell.
Only valid for formula cells. |
org.apache.poi.ss.usermodel.CellType | getCellFormulaType |
Returns the type of the formula cell.
Only valid for formula cells. |
org.apache.poi.ss.usermodel.CellType | getCellFormulaType |
Returns the type of the formula cell.
Only valid for formula cells. |
double | getCellNumericValue |
Returns the value of the cell as a number.
For strings throws an exception. For blank cells we return a 0. |
double | getCellNumericValue |
Returns the value of the cell as a number.
For strings throws an exception. For blank cells we return a 0. |
double | getCellNumericValue |
Returns the value of the cell as a number.
For strings throws an exception. For blank cells we return a 0. |
String | getCellStringValue |
Returns the value of the cell as a string - for numeric cells throws an
exception.
For blank cells returns an empty string. For formula cells that are not string formulas, returns empty string |
String | getCellStringValue |
Returns the value of the cell as a string - for numeric cells throws an
exception.
For blank cells returns an empty string. For formula cells that are not string formulas, returns empty string |
String | getCellStringValue |
Returns the value of the cell as a string - for numeric cells throws an
exception.
For blank cells returns an empty string. For formula cells that are not string formulas, returns empty string |
org.apache.poi.ss.usermodel.CellType | getCellType |
Returns the cell type (numeric, formula, string...)
|
org.apache.poi.ss.usermodel.CellType | getCellType |
Returns the cell type (numeric, formula, string...)
|
org.apache.poi.ss.usermodel.CellType | getCellType |
Returns the cell type (numeric, formula, string...)
|
int | getFirstCellNum |
Returns the number of the first cell contained in this row (the 1-based
column number of the first cell).
|
int | getFirstCellNum |
Returns the number of the first cell contained in this row (the 1-based
column number of the first cell).
|
int | getFirstRowNum |
Returns the first row on the sheet
|
int | getFirstRowNum |
Returns the first row on the sheet
|
int | getLastCellNum |
Returns the index of the last cell contained in this row (the 1-based
column number of the last cell).
|
int | getLastCellNum |
Returns the index of the last cell contained in this row (the 1-based
column number of the last cell).
|
int | getLastRowNum |
Returns the number of the last row on the sheet.
Owing to idiosyncrasies in the excel file format, if the result of calling this method is one, you can't tell if that means there are zero rows on the sheet, or one at the first position. For that case, additionally call org.apache.poi.ss.usermodel.Sheet.getPhysicalNumberOfRows()
to find out if there is a row at position zero or not. |
int | getLastRowNum |
Returns the number of the last row on the sheet.
Owing to idiosyncrasies in the excel file format, if the result of calling this method is one, you can't tell if that means there are zero rows on the sheet, or one at the first position. For that case, additionally call org.apache.poi.ss.usermodel.Sheet.getPhysicalNumberOfRows()
to find out if there is a row at position zero or not. |
int | getNumberOfSheets() |
Returns the number of spreadsheets in the workbook
|
int | getSheetIndex |
Returns the index of the sheet with the given name.
Returns 1 if sheetName is
null |
String | getSheetName |
Returns the sheet name for the specified index
|
org.apache.poi.ss.usermodel.Workbook | getWorkbook() |
Returns internal class of the workbook,
null if file isn't
not loaded.Please note that if you change workbook using API of returned object and want to save workbook to a file, you need to call setChanged() |
boolean | isLoaded() |
Returns
true if workbook is loaded from file. |
void | readFile() |
Loads the workbook from the file.
Warning! All unsaved data (if any) in the workbook is lost after this method is called. |
void | readHyperArray |
Reads one- or two-dimensional
HyperArray data from the sheet
starting at the given cell. |
void | readHyperArray |
Reads one- or two-dimensional
HyperArray data from the sheet
starting at the given cell. |
void | readHyperArray |
Reads one- or two-dimensional
HyperArray data from the sheet
starting at the given cell. |
int | readTableFunction |
Reads the table function from the sheet starting at the row with index
rowIndex :- arguments are read from column at columnIndex - values are read from column at columnIndex + 1 If there is not enough data in the sheet to fill in the length , then table function gets less points.Method returns the actual number of table function points read from the sheet. |
int | readTableFunction |
Reads the table function from the sheet starting at the row of the given
cell:
- arguments are read from column of the given cell - values are read from column next to the given cell If there is not enough data in the sheet to fill in the length , then table function gets less points.Method returns the actual number of table function points read from the sheet. |
int | readTableFunction |
Reads the table function from the sheet starting at the row with index
rowIndex :- arguments are read from column at columnIndex - values are read from column at columnIndex + 1 If there is not enough data in the sheet to fill in the length , then table function gets less points.Method returns the actual number of table function points read from the sheet. |
void | setCellFormula |
Sets formula for this cell.
Note, this method only sets the formula string and does not calculate the formula value. |
void | setCellFormula |
Sets formula for this cell.
Note, this method only sets the formula string and does not calculate the formula value. |
void | setCellFormula |
Sets formula for this cell.
Note, this method only sets the formula string and does not calculate the formula value. |
void | setCellValue |
Sets a boolean value for the cell.
|
void | setCellValue |
Sets a boolean value for the cell.
|
void | setCellValue |
Sets a boolean value for the cell.
|
void | setCellValue |
Sets a numeric value for the cell.
|
void | setCellValue |
Sets a numeric value for the cell.
|
void | setCellValue |
Sets a numeric value for the cell.
|
void | setCellValue |
Sets a string value for the cell.
|
void | setCellValue |
Sets a string value for the cell.
|
void | setCellValue |
Sets a string value for the cell.
|
void | setCellValue |
Sets a date value for the cell.
|
void | setCellValue |
Sets a date value for the cell.
|
void | setCellValue |
Sets a date value for the cell.
|
void | setChanged() |
This method may be used to tell AnyLogic that this workbook has unsaved
changes and should be written on
writeFile() or included to the
model snapshot if it has such
setting.This method should be used when you manually change the workbook via getWorkbook() .All setCell*() etc. |
void | setFileName |
Switches this object to work with another file.
Method does nothing if the given file name is the same as at the current workbook. Any loaded or unsaved data (if any) in this workbook remains as is until you manually call readFile() .Method may be used for loading workbook from another file as well as for saving changed workbook to some other location. |
String | toString() | |
int | writeDataSet |
Writes the given data set to the sheet starting at the given cell.
|
int | writeDataSet |
Writes the given data set to the sheet starting at the given cell.
|
int | writeDataSet |
Writes the given data set to the sheet starting at the given cell.
|
void | writeFile() |
Stores the current workbook to the file.
Workbook should be loaded. Unchanged workbooks (workbooks without any unsaved modifications) aren't saved. For saving to another location please call setFileName(String)
before this method. |
void | writeFile |
Stores the current workbook to the file.
Workbook should be loaded. For saving to another location please call setFileName(String)
before this method. |
public static final org.apache.poi.ss.usermodel.CellType CELL_TYPE_BLANK
public static final org.apache.poi.ss.usermodel.CellType CELL_TYPE_BOOLEAN
public static final org.apache.poi.ss.usermodel.CellType CELL_TYPE_ERROR
public static final org.apache.poi.ss.usermodel.CellType CELL_TYPE_FORMULA
public static final org.apache.poi.ss.usermodel.CellType CELL_TYPE_NUMERIC
public static final org.apache.poi.ss.usermodel.CellType CELL_TYPE_STRING
@Deprecated public ExcelFile(String fileName, boolean saveToSnapshot)
public ExcelFile(Presentable owner, String packagePrefix, String fileName, boolean saveToSnapshot)
- Parameters:
owner
- the presentable object owning this shapepackagePrefix
- the package name of original agent where this image is defined, formatted using '/' characters; with '/' character at the beginning and at the endfileName
- the name of the filesaveToSnapshot
-true
: Store all unsaved data (in any) in the workbook to the model snapshot file
If the workbook is changed during model execution and isn't saved to the file, it is stored to the model snapshot - this mode is turnedfalse
: When snapshot is loaded, this class reads the original ExcelTM file. If the file wasn't initially loaded, it isn't loaded during restoring from snapshot.
public void setFileName(String fileName)
Method does nothing if the given file name is the same as at the current workbook.
Any loaded or unsaved data (if any) in this workbook remains as is until you manually call
readFile()
.Method may be used for loading workbook from another file as well as for saving changed workbook to some other location.
- Parameters:
fileName
- the new file name
public void readFile()
Warning! All unsaved data (if any) in the workbook is lost after this method is called.
- See Also:
-
writeFile()
public boolean isLoaded()
true
if workbook is loaded from file.- Returns:
true
if workbook is loaded from file- See Also:
-
readFile()
public void close()
After this function is called, various get***() functions will throw error, until someone calls
readFile()
public org.apache.poi.ss.usermodel.CellType getCellType(int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the cell type - one of
CellType
enums
public org.apache.poi.ss.usermodel.CellType getCellType(String sheetName, int rowIndex, int columnIndex)
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the cell type - one of
CellType
enums
public boolean getCellBooleanValue(int sheetIndex, int rowIndex, int columnIndex)
boolean
.For strings, numbers, and errors, throws an exception.
For blank cells returns
false
.- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a
boolean
public double getCellNumericValue(int sheetIndex, int rowIndex, int columnIndex)
For strings throws an exception.
For blank cells we return a 0.
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a number
public String getCellStringValue(int sheetIndex, int rowIndex, int columnIndex)
For blank cells returns an empty string.
For formula cells that are not string formulas, returns empty string
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a string
public String getCellFormula(int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- formula for the cell
public byte getCellErrorValue(int sheetIndex, int rowIndex, int columnIndex)
For strings, numbers, and booleans, throws an exception.
For blank cells returns a
0
.- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as an error code
public Date getCellDateValue(int sheetIndex, int rowIndex, int columnIndex)
For strings throws an exception.
For blank cells returns
null
. See
org.apache.poi.ss.usermodel.DataFormatter
class for
formatting this date into a string similar to how excel does.- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a
Date
public org.apache.poi.ss.usermodel.Workbook getWorkbook()
null
if file isn't
not loaded.Please note that if you change workbook using API of returned object and want to save workbook to a file, you need to call
setChanged()
- Returns:
- internal class of the workbook,
null
if file isn't not loaded
public boolean getCellBooleanValue(String sheetName, int rowIndex, int columnIndex)
boolean
.For strings, numbers, and errors, throws an exception.
For blank cells returns
false
.- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a
boolean
public double getCellNumericValue(String sheetName, int rowIndex, int columnIndex)
For strings throws an exception.
For blank cells we return a 0.
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a number
public String getCellStringValue(String sheetName, int rowIndex, int columnIndex)
For blank cells returns an empty string.
For formula cells that are not string formulas, returns empty string
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a string
public String getCellFormula(String sheetName, int rowIndex, int columnIndex)
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- formula for the cell
public byte getCellErrorValue(String sheetName, int rowIndex, int columnIndex)
For strings, numbers, and booleans, throws an exception.
For blank cells returns a
0
.- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as an error code
public Date getCellDateValue(String sheetName, int rowIndex, int columnIndex)
For strings throws an exception.
For blank cells returns
null
. See
org.apache.poi.ss.usermodel.DataFormatter
class for
formatting this date into a string similar to how excel does.- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the value of the cell as a
Date
public org.apache.poi.ss.usermodel.CellType getCellType(String cellName)
- Parameters:
cellName
- the full name of the cell- Returns:
- the cell type - one of
CellType
enums
public boolean getCellBooleanValue(String cellName)
boolean
.For strings, numbers, and errors, throws an exception.
For blank cells returns
false
.- Parameters:
cellName
- the full name of the cell- Returns:
- the value of the cell as a
boolean
public double getCellNumericValue(String cellName)
For strings throws an exception.
For blank cells we return a 0.
- Parameters:
cellName
- the full name of the cell- Returns:
- the value of the cell as a number
public String getCellStringValue(String cellName)
For blank cells returns an empty string.
For formula cells that are not string formulas, returns empty string
- Parameters:
cellName
- the full name of the cell- Returns:
- the value of the cell as a string
public String getCellFormula(String cellName)
- Parameters:
cellName
- the full name of the cell- Returns:
- formula for the cell
public byte getCellErrorValue(String cellName)
For strings, numbers, and booleans, throws an exception.
For blank cells returns a
0
.- Parameters:
cellName
- the full name of the cell- Returns:
- the value of the cell as an error code
public Date getCellDateValue(String cellName)
For strings throws an exception.
For blank cells returns
null
. See
org.apache.poi.ss.usermodel.DataFormatter
class for
formatting this date into a string similar to how excel does.public int getNumberOfSheets()
- Returns:
- the number of spreadsheets in the workbook
public int getLastRowNum(int sheetIndex)
Owing to idiosyncrasies in the excel file format, if the result of calling this method is one, you can't tell if that means there are zero rows on the sheet, or one at the first position.
For that case, additionally call
org.apache.poi.ss.usermodel.Sheet.getPhysicalNumberOfRows()
to find out if there is a row at position zero or not.- Parameters:
sheetIndex
- the index of the spreadsheet, 1-based- Returns:
- the number of the last row contained in this sheet, one-based.
public int getLastRowNum(String sheetName)
Owing to idiosyncrasies in the excel file format, if the result of calling this method is one, you can't tell if that means there are zero rows on the sheet, or one at the first position.
For that case, additionally call
org.apache.poi.ss.usermodel.Sheet.getPhysicalNumberOfRows()
to find out if there is a row at position zero or not.- Parameters:
sheetName
- the name of the sheet- Returns:
- the number of the last row contained in this sheet, one-based.
public int getFirstRowNum(int sheetIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-based- Returns:
- the number of the first logical row on the sheet, one-based
public int getFirstRowNum(String sheetName)
- Parameters:
sheetName
- the name of the sheet- Returns:
- the number of the first logical row on the sheet, one-based
public int getFirstCellNum(int sheetIndex, int rowIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-based- Returns:
- the number representing the first logical cell in the row (one-based), or 0 if the row does not contain any cells.
public int getFirstCellNum(String sheetName, int rowIndex)
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-based- Returns:
- the number representing the first logical cell in the row (one-based), or 0 if the row does not contain any cells.
public int getLastCellNum(int sheetIndex, int rowIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-based- Returns:
- short representing the last logical cell in the row (one-based), or 0 if the row does not contain any cells.
public int getLastCellNum(String sheetName, int rowIndex)
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-based- Returns:
- short representing the last logical cell in the row (one-based), or 0 if the row does not contain any cells.
public boolean cellExists(int sheetIndex, int rowIndex, int columnIndex)
true
if the cell at the given position exists in the
workbook- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
true
if the cell at the given position exists in the workbook,false
otherwise
public boolean cellExists(String sheetName, int rowIndex, int columnIndex)
true
if the cell at the given position exists in the
workbook- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
true
if the cell at the given position exists in the workbook,false
otherwise
public boolean cellExists(String cellName)
true
if the cell at the given position exists in the
workbook- Parameters:
cellName
- the full name of the cell- Returns:
true
if the cell at the given position exists in the workbook,false
otherwise
public void clearCell(int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public int readTableFunction(TableFunction tableFunction, int sheetIndex, int rowIndex, int columnIndex, int length)
rowIndex
:- arguments are read from column at
columnIndex
- values are read from column at
columnIndex + 1
If there is not enough data in the sheet to fill in the
length
, then table function gets less points.Method returns the actual number of table function points read from the sheet.
- Parameters:
tableFunction
- the table function to fillsheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-basedlength
- the number of table function points to read- Returns:
- the actual number of table function points read from the sheet
public int readTableFunction(TableFunction tableFunction, String sheetName, int rowIndex, int columnIndex, int length)
rowIndex
:- arguments are read from column at
columnIndex
- values are read from column at
columnIndex + 1
If there is not enough data in the sheet to fill in the
length
, then table function gets less points.Method returns the actual number of table function points read from the sheet.
- Parameters:
tableFunction
- the table function to fillsheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-basedlength
- the number of table function points to read- Returns:
- the actual number of table function points read from the sheet
public int readTableFunction(TableFunction tableFunction, String cellName, int length)
- arguments are read from column of the given cell
- values are read from column next to the given cell
If there is not enough data in the sheet to fill in the
length
, then table function gets less points.Method returns the actual number of table function points read from the sheet.
- Parameters:
tableFunction
- the table function to fillcellName
- the full name of the celllength
- the number of table function points to read- Returns:
- the actual number of table function points read from the sheet
public org.apache.poi.ss.usermodel.CellType getCellFormulaType(int sheetIndex, int rowIndex, int columnIndex)
Only valid for formula cells.
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- one of one of
CellType
enums depending on the cached value of the formula
public org.apache.poi.ss.usermodel.CellType getCellFormulaType(String sheetName, int rowIndex, int columnIndex)
Only valid for formula cells.
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- one of one of
CellType
enums depending on the cached value of the formula
public org.apache.poi.ss.usermodel.CellType getCellFormulaType(String cellName)
Only valid for formula cells.
- Parameters:
cellName
- the full name of the cell- Returns:
- one of one of
CellType
enums depending on the cached value of the formula
public String getSheetName(int sheetIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-based- Returns:
- the sheet name for the specified index
public int getSheetIndex(String sheetName)
Returns
1
if sheetName
is
null
- Parameters:
sheetName
- the sheet name- Returns:
- the index of the spreadsheet with the specified name, 1-based
public void readHyperArray(HyperArray array, int sheetIndex, int rowIndex, int columnIndex, boolean dim1AcrossRows)
HyperArray
data from the sheet
starting at the given cell.- Parameters:
array
- theHyperArray
to write data to, should have 1 or 2 dimensions.sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-baseddim1AcrossRows
- usetrue
to read the data corresponding to the first dimension, across the sheet rows (e.g. in this mode data for one-dimensional array is loaded from the sheet column)
public void readHyperArray(HyperArray array, String sheetName, int rowIndex, int columnIndex, boolean dim1AcrossRows)
HyperArray
data from the sheet
starting at the given cell.- Parameters:
array
- theHyperArray
to write data to, should have 1 or 2 dimensions.sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-baseddim1AcrossRows
- usetrue
to read the data corresponding to the first dimension, across the sheet rows (e.g. in this mode data for one-dimensional array is loaded from the sheet column)
public void readHyperArray(HyperArray array, String cellName, boolean dim1AcrossRows)
HyperArray
data from the sheet
starting at the given cell.- Parameters:
array
- theHyperArray
to write data to, should have 1 or 2 dimensions.cellName
- the full name of the celldim1AcrossRows
- usetrue
to read the data corresponding to the first dimension, across the sheet rows (e.g. in this mode data for one-dimensional array is loaded from the sheet column)
public void writeFile()
Workbook should be loaded.
Unchanged workbooks (workbooks without any unsaved modifications) aren't saved.
For saving to another location please call
setFileName(String)
before this method.public void writeFile(boolean force)
Workbook should be loaded.
For saving to another location please call
setFileName(String)
before this method.- Parameters:
force
- iftrue
the workbook will be saved to the file even if it is unchanged- See Also:
-
writeFile()
readFile()
setFileName(String)
setChanged()
public void setChanged()
writeFile()
or included to the
model snapshot if it has such
setting.This method should be used when you manually change the workbook via
getWorkbook()
.All
setCell*()
etc. methods automatically mark workbook as
'changed'- See Also:
-
writeFile()
getWorkbook()
public void createCell(int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void createCell(String sheetName, int rowIndex, int columnIndex)
- Parameters:
sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void createCell(String cellName)
- Parameters:
cellName
- the full name of the cell
public void setCellValue(boolean value, int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
value
- the boolean value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than boolean are changed to boolean cells.sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(double value, int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
value
- the numeric value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than numeric are changed to numeric cells.sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(String value, int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
value
- the value to set this cell to. For formula cells the formula string is set. Cells with types other than string are changed to string cells. If value isnull
then cell is changed to a Blank cell.sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(Date value, int sheetIndex, int rowIndex, int columnIndex)
- Parameters:
value
- the date value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than numeric are changed to numeric cells.sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellFormula(String formula, int sheetIndex, int rowIndex, int columnIndex)
Note, this method only sets the formula string and does not calculate the formula value. To set the 'precalculated' value use
setCellValue(...)
method- Parameters:
formula
- the formula to set, e.g."SUM(C4:E4)"
. If this argument isnull
then the current formula is removed.sheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(boolean value, String sheetName, int rowIndex, int columnIndex)
- Parameters:
value
- the boolean value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than boolean are changed to boolean cells.sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(double value, String sheetName, int rowIndex, int columnIndex)
- Parameters:
value
- the numeric value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than numeric are changed to numeric cells.sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(String value, String sheetName, int rowIndex, int columnIndex)
- Parameters:
value
- the value to set this cell to. For formula cells the formula string is set. Cells with types other than string are changed to string cells. If value isnull
then cell is changed to a Blank cell.sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(Date value, String sheetName, int rowIndex, int columnIndex)
- Parameters:
value
- the date value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than numeric are changed to numeric cells.sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellFormula(String formula, String sheetName, int rowIndex, int columnIndex)
Note, this method only sets the formula string and does not calculate the formula value. To set the 'precalculated' value use
setCellValue(...)
method- Parameters:
formula
- the formula to set, e.g."SUM(C4:E4)"
. If this argument isnull
then the current formula is removed.sheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based
public void setCellValue(boolean value, String cellName)
- Parameters:
value
- the boolean value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than boolean are changed to boolean cells.cellName
- the full name of the cell
public void setCellValue(double value, String cellName)
- Parameters:
value
- the numeric value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than numeric are changed to numeric cells.cellName
- the full name of the cell
public void setCellValue(String value, String cellName)
- Parameters:
value
- the value to set this cell to. For formula cells the formula string is set. Cells with types other than string are changed to string cells. If value isnull
then cell is changed to a Blank cell.cellName
- the full name of the cell
public void setCellValue(Date value, String cellName)
- Parameters:
value
- the date value to set this cell to. For formula cells the 'precalculated' value is set. Cells with types other than numeric are changed to numeric cells.cellName
- the full name of the cell
public void setCellFormula(String formula, String cellName)
Note, this method only sets the formula string and does not calculate the formula value. To set the 'precalculated' value use
setCellValue(...)
method- Parameters:
formula
- the formula to set, e.g."SUM(C4:E4)"
. If this argument isnull
then the current formula is removed.cellName
- the full name of the cell
public String toString()
public int writeDataSet(DataSet dataSet, int sheetIndex, int rowIndex, int columnIndex)
X
and Y
components.- Parameters:
dataSet
- the data set to store in the sheetsheetIndex
- the index of the spreadsheet, 1-basedrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the size of the given dataset
public int writeDataSet(DataSet dataSet, String sheetName, int rowIndex, int columnIndex)
X
and Y
components.- Parameters:
dataSet
- the data set to store in the sheetsheetName
- the name of the sheetrowIndex
- the index of the cell row, 1-basedcolumnIndex
- the index of the cell column, 1-based- Returns:
- the size of the given dataset
public int writeDataSet(DataSet dataSet, String cellName)
X
and Y
components.- Parameters:
dataSet
- the data set to store in the sheetcellName
- the full name of the cell- Returns:
- the size of the given dataset
public void evaluateFormulas()
The cells are left as formula cells. Be aware that your cells will hold both the formula, and the result. If you want the cell replaced with the result of the formula, use method
org.apache.poi.ss.usermodel.Cell.evaluateInCell(org.apache.poi.ss.usermodel.Cell)