Package io.github.the_sdet.excel
Class ExcelUtils
java.lang.Object
io.github.the_sdet.excel.ExcelUtils
This class handles all Excel related Utilities and Helper methods
- Author:
- Pabitra Swain ([email protected])
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetHeaderList(String filepath, String sheetName) Retrieves the headers from Excel.getValuesOfColumn(String filepath, String sheetName, int column, boolean skipHeader) This method fetches entries present in a particular column by column index.getValuesOfColumn(String filepath, String sheetName, String columnHeader, boolean skipHeader) This method fetches entries present in a particular column by column header.getValuesOfRow(String filepath, String sheetName, int row, boolean skipFirstColumn) This method fetches entries present in a particular row by row index.getValuesOfRow(String filepath, String sheetName, String rowHeader, boolean skipFirstColumn) This method fetches entries present in a particular row by row header.readExcelSheet(String filepath, String sheetName) Reads an Excel sheet and returns a list of maps containing the data.readExcelSheet(String filepath, String sheetName, boolean skipFirstRow) Reads an Excel sheet and returns a list of maps containing the data, optionally skipping the first row.
-
Constructor Details
-
ExcelUtils
public ExcelUtils()
-
-
Method Details
-
getHeaderList
Retrieves the headers from Excel.- Parameters:
filepath- filename with pathsheetName- 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 pathsheetName- name of the sheetcolumn- column indexskipHeader- 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 pathsheetName- name of the sheetcolumnHeader- header nameskipHeader- 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 pathsheetName- name of the sheetrow- row indexskipFirstColumn- 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 pathsheetName- name of the sheetrowHeader- row header or 1st value of rowskipFirstColumn- 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 pathsheetName- 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 pathsheetName- name of the sheetskipFirstRow- 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
-