Package taro.spreadsheet
Class SpreadsheetReader
- java.lang.Object
-
- taro.spreadsheet.SpreadsheetReader
-
public class SpreadsheetReader extends Object
Very simple utility to help read a POI sheet within an Excel (.xlsx) file. Does not work with .xls files. The getValue and getStringValue methods return the TRIMMED content of the cell, and return an empty String if the cell doesn't exist or is empty. The getNumericValue method returns 0 if the cell doesn't exist or is empty. It throws an exception if the value cannot be parsed to a number. The getDateValue method returns null if the cell doesn't exist or is empty, and throws an exception if the value is not a date.
-
-
Constructor Summary
Constructors Constructor Description SpreadsheetReader(org.apache.poi.ss.usermodel.Sheet sheet)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.poi.ss.usermodel.CellgetCell(int columnIndex, int rowIndex)org.apache.poi.ss.usermodel.CellgetCell(String cellId)static StringgetCellAddress(int col, int row)org.apache.poi.ss.usermodel.CellTypegetCellType(int col, int row)static intgetColumnIndex(String cellId)Gets the 0-based index (used by POI) of the column given a cellId in Excel notation, which must be one or more letters (case-insensitive) followed by an integer.DategetDateValue(int columnIndex, int rowIndex)Returns the Date content of the cell, or null if the cell doesn't exist or is empty.DategetDateValue(String cellId)DategetDateValue(org.apache.poi.ss.usermodel.Cell cell)intgetNumCols(int rowNum)DoublegetNumericValue(int columnIndex, int rowIndex)Returns the numeric content of the cell, or 0 if the cell doesn't exist or is empty.DoublegetNumericValue(String cellId)Returns the numeric content of the cell, or 0 if the cell doesn't exist or is empty.DoublegetNumericValue(org.apache.poi.ss.usermodel.Cell cell)intgetNumRows()org.apache.poi.ss.usermodel.SheetgetPoiSheet()static intgetRowIndex(String cellId)Gets the 0-based index (used by POI) of the row given a cellId in Excel notation, which must be one or more letters (case-insensitive) followed by an integer.StringgetSheetName()StringgetStringValue(int columnIndex, int rowIndex)Returns the trimmed content of the cell as a String, or an empty String if the cell doesn't exist or is empty.StringgetStringValue(String cellId)Returns the trimmed content of the cell as a String, or an empty String if the cell doesn't exist or is empty.StringgetStringValue(org.apache.poi.ss.usermodel.Cell cell)Returns the trimmed content of the cell as a String, or an empty String if the cell doesn't exist or is empty.StringgetValue(int colIndex, int rowIndex)Attempts to convert all values to a string.StringgetValue(String cellId)Attempts to convert all values to a string.StringgetValue(org.apache.poi.ss.usermodel.Cell cell)Attempts to convert all values to a string.booleanisNumeric(int col, int row)booleanisString(int col, int row)String[]readAcross(String startingCell, int num)double[]readAcrossNumeric(String startingCell, int num)List<String>readAcrossUntilBlank(String startingCell)String[]readDown(String startingCell, int num)double[]readDownNumeric(String startingCell, int num)List<String>readDownUntilBlank(String startingCell)String[][]readSheet()booleanrowHasData(int rowIndex)
-
-
-
Method Detail
-
getColumnIndex
public static int getColumnIndex(String cellId)
Gets the 0-based index (used by POI) of the column given a cellId in Excel notation, which must be one or more letters (case-insensitive) followed by an integer. i.e. B7 (which returns 1) or AR1677 (which returns 43). Throws an IllegalArgumentException if the cellId is malformed
-
getRowIndex
public static int getRowIndex(String cellId)
Gets the 0-based index (used by POI) of the row given a cellId in Excel notation, which must be one or more letters (case-insensitive) followed by an integer. i.e. B7 (which returns 6) or BR1677 (which returns 1676) Throws an IllegalArgumentException if the cellId is malformed
-
getCellAddress
public static String getCellAddress(int col, int row)
-
getPoiSheet
public org.apache.poi.ss.usermodel.Sheet getPoiSheet()
-
getNumRows
public int getNumRows()
-
getNumCols
public int getNumCols(int rowNum)
-
getValue
public String getValue(String cellId)
Attempts to convert all values to a string. Returns the trimmed content of the cell, or an empty String if the cell doesn't exist or is empty.
-
getValue
public String getValue(int colIndex, int rowIndex)
Attempts to convert all values to a string. Returns the trimmed content of the cell, or an empty String if the cell doesn't exist or is empty.
-
getValue
public String getValue(org.apache.poi.ss.usermodel.Cell cell)
Attempts to convert all values to a string. Returns the trimmed content of the cell, or an empty String if the cell doesn't exist or is empty.
-
getStringValue
public String getStringValue(String cellId)
Returns the trimmed content of the cell as a String, or an empty String if the cell doesn't exist or is empty.
-
getStringValue
public String getStringValue(int columnIndex, int rowIndex)
Returns the trimmed content of the cell as a String, or an empty String if the cell doesn't exist or is empty.
-
getStringValue
public String getStringValue(org.apache.poi.ss.usermodel.Cell cell)
Returns the trimmed content of the cell as a String, or an empty String if the cell doesn't exist or is empty.
-
getNumericValue
public Double getNumericValue(String cellId)
Returns the numeric content of the cell, or 0 if the cell doesn't exist or is empty.
-
getNumericValue
public Double getNumericValue(int columnIndex, int rowIndex)
Returns the numeric content of the cell, or 0 if the cell doesn't exist or is empty.
-
getNumericValue
public Double getNumericValue(org.apache.poi.ss.usermodel.Cell cell)
-
getDateValue
public Date getDateValue(int columnIndex, int rowIndex)
Returns the Date content of the cell, or null if the cell doesn't exist or is empty.
-
getDateValue
public Date getDateValue(org.apache.poi.ss.usermodel.Cell cell)
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(String cellId)
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(int columnIndex, int rowIndex)
-
getCellType
public org.apache.poi.ss.usermodel.CellType getCellType(int col, int row)
-
isString
public boolean isString(int col, int row)
-
isNumeric
public boolean isNumeric(int col, int row)
-
readDownNumeric
public double[] readDownNumeric(String startingCell, int num)
-
readAcrossNumeric
public double[] readAcrossNumeric(String startingCell, int num)
-
readSheet
public String[][] readSheet()
-
getSheetName
public String getSheetName()
-
rowHasData
public boolean rowHasData(int rowIndex)
-
-