Package net.sf.basedb.util.excel
Class XlsxToCsvUtil.SheetInfo
java.lang.Object
net.sf.basedb.util.excel.XlsxToCsvUtil.SheetInfo
- Enclosing class:
- XlsxToCsvUtil
public class XlsxToCsvUtil.SheetInfo extends Object
Represents a single sheet in a workbook. Use it to get access to a CSV Input stream
that is generated from the table data. It can also be used to get access to the
actual underlying Cell element for reading data directly.
-
Field Summary
Fields Modifier and Type Field Description private byte[]
csvBytes
private org.apache.poi.ss.usermodel.DataFormatter
dataFormat
private int
firstColumn
private int
firstRow
private org.apache.poi.ss.usermodel.FormulaEvaluator
formulaEval
private int
lastColumn
private int
lastRow
private org.apache.poi.ss.usermodel.Sheet
sheet
-
Constructor Summary
Constructors Constructor Description SheetInfo(org.apache.poi.ss.usermodel.Sheet sheet)
-
Method Summary
Modifier and Type Method Description private XlsxToCsvUtil.CellTypeWithInfo
evaluateFormula(org.apache.poi.ss.usermodel.Cell cell)
org.apache.poi.ss.usermodel.Cell
getCell(int row, int col)
Get the cell at the specified row and column.Date
getCellValueAsDate(org.apache.poi.ss.usermodel.Cell cell, Formatter<Date> parser, boolean nullIfException)
Get the cell value as a date.Double
getCellValueAsNumber(org.apache.poi.ss.usermodel.Cell cell, NumberFormat parser, boolean nullIfException)
Get the cell value as a number.String
getCellValueAsString(org.apache.poi.ss.usermodel.Cell cell)
Get the the cell value as a string.int
getFirstColumn()
Get the column number for the first column that contains data.int
getFirstRow()
Get the row number for the first row that contains data.int
getLastColumn()
Get the column number for the last column that contains data.int
getLastRow()
Get the row number for the last row that contains data.String
getName()
Get the name of the sheet.int
getSize()
Get the size of the CSV in bytes.private void
parseToBytes()
InputStream
parseToCsv()
Convert the sheet to a CSV and get an InputStream for reading the data.
-
Field Details
-
sheet
private final org.apache.poi.ss.usermodel.Sheet sheet -
dataFormat
private final org.apache.poi.ss.usermodel.DataFormatter dataFormat -
formulaEval
private final org.apache.poi.ss.usermodel.FormulaEvaluator formulaEval -
firstRow
private final int firstRow -
lastRow
private final int lastRow -
firstColumn
private final int firstColumn -
lastColumn
private final int lastColumn -
csvBytes
private byte[] csvBytes
-
-
Constructor Details
-
SheetInfo
SheetInfo(org.apache.poi.ss.usermodel.Sheet sheet)
-
-
Method Details
-
getName
Get the name of the sheet. -
getFirstRow
public int getFirstRow()Get the row number for the first row that contains data. -
getLastRow
public int getLastRow()Get the row number for the last row that contains data. -
getFirstColumn
public int getFirstColumn()Get the column number for the first column that contains data. -
getLastColumn
public int getLastColumn()Get the column number for the last column that contains data. -
getCell
public org.apache.poi.ss.usermodel.Cell getCell(int row, int col)Get the cell at the specified row and column.- Returns:
- A Cell instance or null
-
getCellValueAsString
Get the the cell value as a string. Numeric cells are are checked if the seem to have a date-like format syntax (with or without time). If so, the value is formatted with the date or timestamp formatter, otherwise with the number formatter. If the required formatter has not been set, the value is formatted with the built-in formatter from Excel. -
getCellValueAsNumber
public Double getCellValueAsNumber(org.apache.poi.ss.usermodel.Cell cell, NumberFormat parser, boolean nullIfException)Get the cell value as a number. If the cell is a numeric cell, the value is returned directly, otherwise the given parser is used to parse the string data from cell, viaType.parseString(String, NumberFormat, boolean)
-
getCellValueAsDate
public Date getCellValueAsDate(org.apache.poi.ss.usermodel.Cell cell, Formatter<Date> parser, boolean nullIfException)Get the cell value as a date. If the cell is a numeric cell, the value is returned directly as if it was a date (the style format string is NOT checked), otherwise the given parser is used to parse the string data from cell, viaType.parseString(String, Formatter, boolean)
-
evaluateFormula
-
parseToCsv
Convert the sheet to a CSV and get an InputStream for reading the data. Note that the CSV will only contain data for the range of cells between firstRow, lastRow, firstColumn and lastColumn. -
getSize
public int getSize()Get the size of the CSV in bytes.- Since:
- 3.17.1
-
parseToBytes
private void parseToBytes()
-