class ExcelUtil extends java.lang.Object
Utility class to read XML based Microsoft Excel files.
Modifiers | Name | Description |
---|---|---|
static enum |
ExcelUtil.EXCEL |
Constants related to Excel processing |
static class |
ExcelUtil.ExcelRow |
Class to represent a row from an Excel worksheet. |
Type | Name and description |
---|---|
static org.slf4j.Logger |
log A logger to use |
Constructor and description |
---|
ExcelUtil
() |
Type Params | Return Type | Name and description |
---|---|---|
|
static java.util.Map |
indexMap(java.util.List<java.lang.String> vals) Return a map of index to value for the provided list of string values. |
|
static java.util.List<java.util.Map> |
readExcelFile(java.io.File inputFile) Read an Excel file into a list of maps. |
|
static java.util.List<java.util.Map> |
readExcelFile(java.io.InputStream input) Read an Excel file in to a list of maps. |
|
static java.util.List<ExcelRow> |
readExcelSheet(java.io.File inputFile, java.lang.String sheetName, java.util.Map params) Read an individual sheet from an Excel file. |
|
static java.util.List<ExcelRow> |
readExcelSheet(java.io.InputStream input, java.lang.String sheetName, java.util.Map params) Read the a sheet of the provided name from the provided input stream. |
|
static java.util.List<java.lang.String> |
readRow(org.apache.poi.xssf.usermodel.XSSFRow row) Read the provided row and return the data as a list of strings. |
|
static java.util.List<java.lang.String> |
readRow(org.apache.poi.xssf.usermodel.XSSFRow row, java.util.Map params) Read the provided row and return the data as a list of strings. |
|
static java.util.List<ExcelRow> |
readSheet(org.apache.poi.xssf.usermodel.XSSFWorkbook wb, java.lang.String sheetName, java.util.Map params) Read a sheet named as the provided name from the provided workbook. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Return a map of index to value for the provided list of string values.
vals
- A list of stringsRead an Excel file into a list of maps.
inputFile
- Th Excel file.Read an Excel file in to a list of maps.
input
- An input stream of the Excel file data.Read an individual sheet from an Excel file. Reading from an Excel is not straightforward or easy. These utility methods might might help you out if: - The Excel sheet is formatted like a data table where a header row contains the field names and the remainder of the sheet contains rows of data. - There is only a single format for dates in the sheet. The default behavior is to be tolerant of read failures, writing warning messages to the log while ignoring the value. To fail on error, see the failOnError parameter.
inputFile
- The Excel file to read.sheetName
- The name of the sheet.params.raws
- Optional list of fields to treat as raw values.params.integers
- Optional list of fields to interpret as integers.params.dates
- Optional map of data parsing params.params.dates.sourceFormat
- The format (DateFormat) used for dates
in the Excel file.params.dates.outputFormat
- The formatter (DateFormat) used to
output dates as Strings.params.dates.fields
- A list of fields that should be parsed as dates.failOnError
- If there is an error reading the file, throw a
ParseException.firstRowNum
- Integer The first row to read. Use this parameter to skip
one or more rows at the start of the document before the header row.skipRowNums
- SetskipBlankRows
- Boolean If true, skip over rows that contain no data.skipNullRows
- Boolean If true, skip over rowNums that have a null row.
readExcelSheet attempts to read the entire sheet by accessing the
rows by rowNum in sequential order. There is no guarantee that there
will be no skipped rowNums in an Excel sheet, even if there are no
apparent empty rows. skipNullRows should probably be the default,
but it is an explicit switch for now.Read the a sheet of the provided name from the provided input stream.
input
- The input stream for the Excel filesheetName
- The name of the sheet to readparams
- Optional additional parametersRead the provided row and return the data as a list of strings.
row
- The Excel rowRead the provided row and return the data as a list of strings.
row
- The Excel rowparams.colNameToIdx
- Map of column names to indexparams.dates.sourceFormat
- The format of dates in the Excel fileparams.dates.outputFormat
- The target format of datesparams.dates.fields
- The fields that contain datesparams.raws
- The raw indexes in the dataparams.integerIndexes
- The indexes in the data as integersparams.failOnError
- If true, fail if an error is encounteredRead a sheet named as the provided name from the provided workbook.
wb
- The Excel workbooksheetName
- The name of the sheet to readparams
- Optional additional parametersGroovy Documentation