io.nishadc.automationtestingframework.filehandling.ExcelFileHandling Maven / Gradle / Ivy
package io.nishadc.automationtestingframework.filehandling;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import io.nishadc.automationtestingframework.filehandling.exceptions.ExcelFileHandlingException;
import io.nishadc.automationtestingframework.logging.LoggerFactory;
public class ExcelFileHandling {
private static final Logger logger = LoggerFactory.create(ExcelFileHandling.class);
private ExcelFileHandling() {
}
private static ExcelFileType getWorkbookType(String fullWorkbookPath) throws ExcelFileHandlingException {
try {
//parse workbook type from file extension name. Currently restricted to .xls and .xlsx
return ExcelFileType
.valueOf(fullWorkbookPath.substring(fullWorkbookPath.lastIndexOf(".") + 1).toUpperCase());
} catch (IllegalArgumentException e) {
//in case of file extension other than .xls and .xlsx
throw (ExcelFileHandlingException) new ExcelFileHandlingException(
"Invalid file type. Only .xls and .xlsx format is supported.").initCause(e);
}
}
private static List