Class ExcelParser

java.lang.Object
com.inet.excel.parser.ExcelParser

public class ExcelParser extends Object
Component responsible for reading data from Excel document.
  • Constructor Details

    • ExcelParser

      public ExcelParser(Path filePath, boolean hasHeaderRow)
      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

      public String getFileName()
      Returns file name of the Excel document, e.g. "doc.xlsx".
      Returns:
      file name of the Excel document.
    • getColumnNames

      public List<String> getColumnNames(String sheetName)
      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:
      ExcelParser.ExcelParserException - in case of I/O or processing errors.
    • getSheetNames

      public List<String> 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:
      ExcelParser.ExcelParserException - in case of I/O or processing errors.
    • getColumnTypes

      public List<ValueType> getColumnTypes(String sheetName)
      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 takes ValueType.VARCHAR as column's type.
      Parameters:
      sheetName - name of the sheet from Excel document.
      Returns:
      list of column types from specified sheet.
      Throws:
      ExcelParser.ExcelParserException - in case of I/O or processing errors.
    • getRowCount

      public int getRowCount(String sheetName)
      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:
      ExcelParser.ExcelParserException - in case of I/O or processing errors.
    • getRows

      public List<List<Object>> getRows(String sheetName, int firstRowIndex, int lastRowIndex)
      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.
      ExcelParser.ExcelParserException - in case of I/O or processing errors.