我正在開發帶擴展符的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。請澄清。 –