use of org.apache.poi.xssf.usermodel.XSSFRow in project selenium_java by sergueik.
the class ExcelConfiguration method CreateHeader.
@SuppressWarnings("deprecation")
public static XSSFRow CreateHeader(XSSFWorkbook book, XSSFSheet sheet, String[] headers) {
XSSFRow row = sheet.createRow(0);
for (int column = 0; column < headers.length; column++) {
XSSFCell headerCell = row.createCell(column);
XSSFCellStyle headerStyle = book.createCellStyle();
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
headerStyle.setBorderTop(BorderStyle.THIN);
// headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
headerStyle.setLocked(true);
headerCell.setCellStyle(headerStyle);
headerCell.setCellValue(headers[column]);
}
return row;
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project selenium_java by sergueik.
the class ExcelConfiguration method appendExcelDataToMap.
public static HashMap<String, ArrayList<String>> appendExcelDataToMap(XSSFSheet xlSheet) {
XSSFRow row = null;
Map<String, ArrayList<String>> sheetMap = new HashMap<>();
int i = xlSheet.getFirstRowNum() + 1;
for (; i <= xlSheet.getLastRowNum(); i++) {
row = xlSheet.getRow(i);
ArrayList<String> newData = addDataToMap(row, new ArrayList<String>());
sheetMap.put(row.getCell(Configuration.testNameIndex).getStringCellValue(), newData);
}
return (HashMap<String, ArrayList<String>>) sheetMap;
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project selenium_java by sergueik.
the class ExcelConfiguration method appendExcelData.
public static HashMap<String, ArrayList<String>> appendExcelData(XSSFSheet xlSheet, HashMap<String, ArrayList<String>> sheetMap) {
XSSFRow row = null;
int i = xlSheet.getFirstRowNum() + 1;
for (; i <= xlSheet.getLastRowNum(); i++) {
row = xlSheet.getRow(i);
if (sheetMap.get(row.getCell(Configuration.testNameIndex).getStringCellValue()) == null) {
ArrayList<String> newData = addDataToMap(row, new ArrayList<String>());
sheetMap.put(row.getCell(Configuration.testNameIndex).getStringCellValue(), newData);
}
}
return sheetMap;
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project selenium_java by sergueik.
the class ReportData method createExcelFile.
// @SuppressWarnings("deprecation")
public static XSSFWorkbook createExcelFile(HashMap<String, Map<String, ArrayList<String>>> data) {
XSSFWorkbook book = new XSSFWorkbook();
XSSFCellStyle failCelStyle = book.createCellStyle();
XSSFCellStyle passCelStyle = book.createCellStyle();
// http://stackoverflow.com/questions/19145628/auto-size-height-for-rows-in-apache-poi
for (String sheetNameKey : data.keySet()) {
XSSFSheet sheet = book.createSheet(sheetNameKey);
XSSFRow row = ExcelConfiguration.CreateHeader(book, sheet, Configuration.header);
HashMap<String, ArrayList<String>> testMethods = (HashMap<String, ArrayList<String>>) data.get(sheetNameKey);
int l = 1;
for (String testMethod : testMethods.keySet()) {
passCelStyle.setFillForegroundColor(HSSFColor.BRIGHT_GREEN.index);
failCelStyle.setFillForegroundColor(HSSFColor.RED.index);
// XSSFColor myColor = new XSSFColor(XSSFColor.);
// failCelStyle.setFillForegroundColor(myColor);
// converting to poi 3.17
// passCelStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
passCelStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// failCelStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
failCelStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
row = sheet.createRow(l++);
XSSFCell cellName = row.createCell(Configuration.testNameIndex);
cellName.setCellValue(testMethod);
sheet.autoSizeColumn(Configuration.testNameIndex);
ArrayList<String> testData = testMethods.get(testMethod);
XSSFCell cellStatus = row.createCell(Configuration.testStatusIndex);
if ("fail".equalsIgnoreCase(testData.get(Configuration.testStatusIndex))) {
cellStatus.setCellStyle(failCelStyle);
cellStatus.setCellValue(testData.get(Configuration.testStatusIndex));
XSSFCell expCell = row.createCell(Configuration.exceptionMsgIndex);
expCell.setCellValue(testData.get(Configuration.exceptionMsgIndex));
sheet.autoSizeColumn(Configuration.exceptionMsgIndex);
XSSFCell exceptionTraceCell = row.createCell(Configuration.exceptionStackTrace);
exceptionTraceCell.setCellValue(testData.get(Configuration.exceptionStackTrace).trim());
sheet.autoSizeColumn(Configuration.exceptionStackTrace);
XSSFCell locatorCell = row.createCell(Configuration.locatorIndex);
String text = testData.get(Configuration.exceptionStackTrace).trim();
String jsonString = null;
Gson gson = new GsonBuilder().create();
int sIndex = text.indexOf('{');
int eIndex = text.indexOf('}');
jsonString = (sIndex == -1 || eIndex == -1) ? "" : text.substring(sIndex, (eIndex + 1));
ElementLocator locator = gson.fromJson(jsonString, ElementLocator.class);
locatorCell.setCellValue((locator == null) ? "" : locator.toString());
} else {
cellStatus.setCellStyle(passCelStyle);
cellStatus.setCellValue(testData.get(Configuration.testStatusIndex));
sheet.autoSizeColumn(Configuration.testStatusIndex);
XSSFCell expCell = row.createCell(Configuration.exceptionMsgIndex);
expCell.setCellValue(testData.get(Configuration.exceptionMsgIndex));
sheet.autoSizeColumn(Configuration.exceptionMsgIndex);
XSSFCell exceptionTraceCell = row.createCell(Configuration.exceptionStackTrace);
exceptionTraceCell.setCellValue(testData.get(Configuration.exceptionStackTrace).trim());
sheet.autoSizeColumn(Configuration.exceptionStackTrace);
}
}
}
return book;
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project selenium_java by sergueik.
the class ExcelFileWriter method writeToFile.
@Override
public boolean writeToFile(String fileName, List<LocatorModel> dData) {
int i = 0;
try (XSSFWorkbook book = getWorkBook()) {
XSSFSheet sheet = book.createSheet(SHEET_NAME);
for (LocatorModel model : dData) {
XSSFRow row = sheet.createRow(i++);
row.createCell(0).setCellValue(model.getLocatorType());
row.createCell(1).setCellValue(model.getLocatorValue());
}
book.write(new FileOutputStream(new File(ResourceHelper.getResourcePath("excel/") + fileName + ".xlsx")));
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
Aggregations