我正在开发带扩展符的JSF发生我是moficando excel我生成的默认报告,我只需要在生成的单元格中详细应用样式,我只能对样式头进行样式设置。将方法getPhysicalNumberOfCells应用于使用POI生成的单元格?
private void columnsCustomers() {
this.setColumnCustomer(new ArrayList<ValidColumnKey>());
this.getColumnCustomer().add(new ValidColumnKey(1, "Codigo", "code"));
this.getColumnCustomer().add(new ValidColumnKey(2, "Nombre", "name"));
this.getColumnCustomer().add(new ValidColumnKey(3, "Nombre Comercial", "comercialName"));
this.getColumnCustomer().add(new ValidColumnKey(4, "Estado", "isActive"));
}
public void postProcessXLS(Object document) {
HSSFWorkbook wb = (HSSFWorkbook) document;
HSSFSheet sheet = wb.getSheetAt(0);
//HSSFSheet sheet = wb.createSheet(getCustomer().getName());
HSSFRow header = sheet.getRow(0);
HSSFRow rowUser0 = sheet.createRow((short) 0);
HSSFCellStyle styleHeader = (HSSFCellStyle) wb.createCellStyle();
styleHeader.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFFont fontHeader = (HSSFFont) wb.createFont();
fontHeader.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
fontHeader.setColor(HSSFColor.WHITE.index);
styleHeader.setFillForegroundColor(HSSFColor.DARK_BLUE.index);
styleHeader.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
styleHeader.setFont(fontHeader);
styleHeader.setBorderBottom((short) 1);
styleHeader.setBorderLeft((short) 1);
styleHeader.setBorderRight((short) 1);
styleHeader.setBorderTop((short) 1);
HSSFCell indice = rowUser0.createCell((short) 0);
indice.setCellValue("N°");
indice.setCellStyle(styleHeader);
int nro = 1;
for(ValidColumnKey column : this.getColumnCustomer()){
HSSFCell hnro = rowUser0.createCell((short) nro);
hnro.setCellValue(column.getDescripcion());
hnro.setCellStyle(styleHeader);
nro++;
}
HSSFCellStyle styleCellWhite = (HSSFCellStyle) wb.createCellStyle();
HSSFFont fontCellWhite = (HSSFFont) wb.createFont();
fontCellWhite.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
styleCellWhite.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
styleCellWhite.setBorderBottom((short) 1);
styleCellWhite.setBorderLeft((short) 1);
styleCellWhite.setBorderRight((short) 1);
styleCellWhite.setBorderTop((short) 1);
for(int i=0; i < header.getPhysicalNumberOfCells();i++) {
HSSFCell cell = header.getCell(i);
cell.setCellStyle(styleHeader);
}
}
图片:http://s2.subirimagenes.com/otros/previo/thump_8748813excelpoi.jpg
正如你在图像中看到的只是缺少在具体应用练成边缘的风格,我申请的风格,但显然不起作用,该方法将header.getPhysicalNumberOfCells
有人能指导我,他们非常感激。
我也想念你表示,也想把名称放到Excel电子表格中,想用这个代码做,但我是个例外:HSSFSheet sheet = wb.createSheet(“Customer”); – user3123910
你想做什么? header.getPhysicalNumberOfCells循环遍历头部的每个单元格(在Excel中第一行),并强制样式'styleHeader'到每个单元格。这不是必需的,因为您在创建标题单元格时已经这样做了。你也不用styleCellWhite。请澄清。 –