2016-04-05 12 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); 
関連する問題