2016-04-05 195 views
0

我試圖格式化標題,但它失敗了,我不知道爲什麼。下面是代碼,非常簡單。Apache POI風格不適用

而這就是我得到:

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); 

         } 

有沒有人有一個想法如何解決這個問題?

回答

0

小區編號是不正確這裏:

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

它應該是:

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