0
我正在设置标题的样式,我最后一列中的一个也获得了为标题设置的样式。这是我设置设置风格的代码。在Apache POI中设置样式
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(sheetName);
for (int i = 0; i < numberOfMergedRow; i++) {
sheet.addMergedRegion(new CellRangeAddress(i, i, 0, numberOfColumns - 1));
sheet.autoSizeColumn(i);
}
XSSFRow row = sheet.createRow(0);
int l = row.getLastCellNum() + 1;
XSSFCell cell = row.createCell((short) l);
XSSFCellStyle cellStyle = workbook.createCellStyle();
Font headerFont = workbook.createFont();
Set<Integer> keyset = data.keySet();
int rownum = 0;
for (Integer key : keyset) {
row = sheet.createRow(rownum++);
Object[] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr) {
cell = row.createCell(cellnum++);
if (obj instanceof String)
cell.setCellValue((String) obj);
else if (obj instanceof Integer)
cell.setCellValue((Integer) obj);
else if (obj instanceof Double)
cell.setCellValue((Double) obj);
else if (obj instanceof Number)
cell.setCellValue((Double) obj);
}
cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
/* adding heading style */
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerFont.setFontHeightInPoints((short) 12);
cellStyle.setFont(headerFont);
cell.setCellStyle(cellStyle);
我怎么只能在头设置的样式?
使用两种风格,一个是头,一个用于休息吗? – Gagravarr
@ Gagravarr,我应该只使用风格的标题,我只是设置标题的风格,事情是我在数据部分列如何? – pralad