Class ExcelUtils

java.lang.Object
io.github.the_sdet.excel.ExcelUtils

public class ExcelUtils extends Object
This class handles all Excel related Utilities and Helper methods
Author:
Pabitra Swain ([email protected])
  • Constructor Details

    • ExcelUtils

      public ExcelUtils()
  • Method Details

    • getHeaderList

      public static List<String> getHeaderList(String filepath, String sheetName) throws IOException
      Retrieves the headers from Excel.
      Parameters:
      filepath - filename with path
      sheetName - name of the sheet
      Returns:
      List of header strings
      Throws:
      IOException - if an I/O error occurs
    • getValuesOfColumn

      public static ArrayList<String> getValuesOfColumn(String filepath, String sheetName, int column, boolean skipHeader) throws IOException
      This method fetches entries present in a particular column by column index.
      Parameters:
      filepath - filename with path
      sheetName - name of the sheet
      column - column index
      skipHeader - true if header to be excluded
      Returns:
      List of entries present in the specified column
      Throws:
      IOException - if an I/O error occurs
    • getValuesOfColumn

      public static ArrayList<String> getValuesOfColumn(String filepath, String sheetName, String columnHeader, boolean skipHeader) throws IOException
      This method fetches entries present in a particular column by column header.
      Parameters:
      filepath - filename with path
      sheetName - name of the sheet
      columnHeader - header name
      skipHeader - true if header to be excluded
      Returns:
      List of entries present in the specified column
      Throws:
      IOException - if an I/O error occurs
    • getValuesOfRow

      public static ArrayList<String> getValuesOfRow(String filepath, String sheetName, int row, boolean skipFirstColumn) throws IOException
      This method fetches entries present in a particular row by row index.
      Parameters:
      filepath - filename with path
      sheetName - name of the sheet
      row - row index
      skipFirstColumn - true if the first column value to be excluded in case there is a row header
      Returns:
      List of entries present in the specified row
      Throws:
      IOException - if an I/O error occurs
    • getValuesOfRow

      public static ArrayList<String> getValuesOfRow(String filepath, String sheetName, String rowHeader, boolean skipFirstColumn) throws IOException
      This method fetches entries present in a particular row by row header.
      Parameters:
      filepath - filename with path
      sheetName - name of the sheet
      rowHeader - row header or 1st value of row
      skipFirstColumn - true if the first column value to be excluded in case there is a row header
      Returns:
      List of entries present in the specified row
      Throws:
      IOException - if an I/O error occurs
    • readExcelSheet

      public static List<Map<String,String>> readExcelSheet(String filepath, String sheetName) throws IOException
      Reads an Excel sheet and returns a list of maps containing the data. List represents each row and each row contains a map with header as key and value for that header and row
      Parameters:
      filepath - filename with path
      sheetName - name of the sheet
      Returns:
      List of maps representing the data from the Excel sheet
      Throws:
      IOException - if an I/O error occurs
    • readExcelSheet

      public static List<Map<String,String>> readExcelSheet(String filepath, String sheetName, boolean skipFirstRow) throws IOException
      Reads an Excel sheet and returns a list of maps containing the data, optionally skipping the first row. List represents each row and each row contains a map with header as key and value for that header and row
      Parameters:
      filepath - filename with path
      sheetName - name of the sheet
      skipFirstRow - true to skip the first row, false otherwise
      Returns:
      List of maps representing the data from the Excel sheet
      Throws:
      IOException - if an I/O error occurs