Apache POI Style不适用

时间:2016-04-05 07:59:01

标签: java apache-poi cell

我试图格式化标题,但它失败了,我不知道为什么。下面是代码,非常简单。

这就是我得到的:

Image

最后三个单元格未格式化。我试图打印c,但这是正常的。

// Set Cell value in sheet
                        row.createCell(0).setCellValue("Name");
                        // Set Cell value in sheet
                        row.createCell(1).setCellValue("Surname");
                        // Set Cell value in sheet
                        row.createCell(2).setCellValue("ID");
                        // Set Cell value in sheet
                        row.createCell(3).setCellValue("Duration");

                        // Set CellStyle head to the Cells
                        Cell name = sheet.getRow(0).getCell(0);
                        name_head.setCellStyle(head);
                        Cell surname = sheet.getRow(0).getCell(1);
                        surname_head.setCellStyle(head);
                        Cell id_head = sheet.getRow(0).getCell(2);
                        id_head.setCellStyle(head);
                        Cell duration = sheet.getRow(0).getCell(3);
                        duration_haed.setCellStyle(head);

                        // Set Cell value
                        for (int c = 0; c < daysInMonth; c++) {

                            row.createCell(c + 4).setCellValue(c + 1);
                            Cell header = sheet.getRow(0).getCell(c + 1);
                            // Set CellStyle head
                            header.setCellStyle(head);

                        }

有没有人知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

此处的单元格编号不正确:

Cell header = sheet.getRow(0).getCell(c + 1);

应该是:

Cell header = sheet.getRow(0).getCell(c + 4);
相关问题