Package com.inet.excel.parser
Class ExcelParser
java.lang.Object
com.inet.excel.parser.ExcelParser
Component responsible for reading data from Excel document.
-
Constructor Summary
ConstructorsConstructorDescriptionExcelParser(Path filePath, boolean hasHeaderRow) Creates instance responsible for reading data from specified Excel document. -
Method Summary
Modifier and TypeMethodDescriptiongetColumnNames(String sheetName) Returns list containing names of columns from specified sheet.getColumnTypes(String sheetName) Returns list of column types from specified sheet.Returns file name of the Excel document, e.g.intgetRowCount(String sheetName) Returns number of rows included in specified sheet from Excel document.Returns list of rows from specified range.Returns list containing names of all sheets from Excel document, in order of their occurrence in the workbook.
-
Constructor Details
-
ExcelParser
Creates instance responsible for reading data from specified Excel document.- Parameters:
filePath- file path to Excel document.hasHeaderRow- whether first row in sheet represents column headers.- Throws:
IllegalArgumentException- if file path is null.
-
-
Method Details
-
getFileName
Returns file name of the Excel document, e.g. "doc.xlsx".- Returns:
- file name of the Excel document.
-
getColumnNames
Returns list containing names of columns from specified sheet. If sheet contains row representing column headers, values from its cells will be used as column names. In case of cells in column header row, which have no values, column names will be auto-generated. If sheet does not contain row representing column headers, all column names will be auto-generated.- Parameters:
sheetName- name of the sheet from Excel document.- Returns:
- list containing names of columns from specified sheet.
- Throws:
ExcelParserException- in case of I/O or processing errors.
-
getSheetNames
Returns list containing names of all sheets from Excel document, in order of their occurrence in the workbook.- Returns:
- list containing names of all sheets from Excel document.
- Throws:
ExcelParserException- in case of I/O or processing errors.
-
getColumnTypes
Returns list of column types from specified sheet. It probes limited number of cells belonging to columns in order to recognize their common value type. In case of columns with values of mixed types, it takesValueType.VARCHARas column's type.- Parameters:
sheetName- name of the sheet from Excel document.- Returns:
- list of column types from specified sheet.
- Throws:
ExcelParserException- in case of I/O or processing errors.
-
getRowCount
Returns number of rows included in specified sheet from Excel document.- Parameters:
sheetName- name of the sheet from Excel document.- Returns:
- number of rows included in specified sheet from Excel document.
- Throws:
ExcelParserException- in case of I/O or processing errors.
-
getRows
Returns list of rows from specified range. Every element in resulting list represents cell values from single row. Resulting list contains data of rows in order of their occurrence in the sheet. Cells with no values are represented as empty strings.- Parameters:
sheetName- name of the sheet from Excel document.firstRowIndex- index of the first row, which should be included in the list.lastRowIndex- index of the last row, which should be included in the list.- Returns:
- list of rows from specified range.
- Throws:
IllegalArgumentException- if one of specified indexes is smaller than 1; if first index is greater than last index.ExcelParserException- in case of I/O or processing errors.
-