Selenium webdriver 无法使用setFillBackgroundColor为excel单元格着色+;阿帕奇poi
我使用了下面的脚本,但excel单元格并没有得到绿色。其余所有东西都工作正常,只是绿色填充颜色不工作 公共类createExcel{Selenium webdriver 无法使用setFillBackgroundColor为excel单元格着色+;阿帕奇poi,selenium-webdriver,apache-poi,Selenium Webdriver,Apache Poi,我使用了下面的脚本,但excel单元格并没有得到绿色。其余所有东西都工作正常,只是绿色填充颜色不工作 公共类createExcel{ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(&
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Color Test");
Row row = sheet.createRow(0);
CellStyle style = workbook.createCellStyle();
// style.setFillForegroundColor(IndexedColors.GREEN.getIndex());
style.setFillBackgroundColor(IndexedColorMap.BLUE.getIndex());
style.setFillBackgroundColor(IndexedColors.BLUE.getIndex());
// style.setFillPattern();
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font font = workbook.createFont();
font.setColor(IndexedColors.RED.getIndex());
style.setFont(font);
Cell cell1 = row.createCell(0);
cell1.setCellValue("ID");
cell1.setCellStyle(style);
Cell cell2 = row.createCell(1);
cell2.setCellValue("NAME");
cell2.setCellStyle(style);
FileOutputStream fos = new FileOutputStream(new File("D:\\backup\\Mine\\applications\\PuneetPRo\\logged.xlsx"));
workbook.write(fos);
fos.close();
System.out.println("Done");
}
}要设置单元格颜色,请使用
style.setFillForegroundColor(IndexedColors.BLUE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
而不是
style.setFillBackgroundColor(IndexedColors.BLUE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
看看这是否解决了您的问题: