41行目以降のタイトルからわかるように、デバッグを行ってもコードは正常に動作していますが、私のスタイルは適用されません。Apache POI Cellstyleは何らかの理由で41行目以降に適用されません
private void writeTable(Table table,Row row,Workbook wb){
CellStyle cellStyle = wb.createCellStyle();
if(row.getRowNum() % 2 == 0) {
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
cellStyle.setWrapText(true);
cellStyle.setTopBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
cellStyle.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setBorderRight(CellStyle.BORDER_THIN);
cellStyle.setRightBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
cellStyle.setLeftBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
}else{
cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
cellStyle.setWrapText(true);
cellStyle.setTopBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
cellStyle.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setBorderRight(CellStyle.BORDER_THIN);
cellStyle.setRightBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
cellStyle.setLeftBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
}
Cell cell = row.createCell(0);
cell.setCellValue(Table.index);
cell.setCellStyle(cellStyle);
cell = row.createCell(1);
cell.setCellValue(strCorrecter(Table.Name).isEmpty() ? "-" : strCorrecter(Table.Name));
cell.setCellStyle(cellStyle);
cell = row.createCell(2);
cell.setCellValue(strCorrecter(Table.Surname.toString()).isEmpty() ? "-" : strCorrecter(Table.Surname.toString()));
cell.setCellStyle(cellStyle);
cell = row.createCell(3);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(4);
cell.setCellValue(strCorrecter(Table.Age.toString()).isEmpty() ? "-" : strCorrecter(Table.Age.toString()));
cell.setCellStyle(cellStyle);
cell = row.createCell(5);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell =row.createCell(6);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(7);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(8);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(9);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(10);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(11);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(12);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(13);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
cell = row.createCell(14);
cell.setCellValue("TODO");
cell.setCellStyle(cellStyle);
}
と私はすべての行が関数の先頭であればelse文を通過することを参照してください。
私の関数です。しかし、私はExcelファイルを見ても属性がないようです。 /セル大幅
でファイルの拡張子を変更(HTTPS:/ /support.office.com/en-us/article/Excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3)ブックのユニークなセルフォーマット/セルスタイルの最大数。だから**各単一の行にセルスタイルを作成しないでください**。私が見る限り、あなたは** 2つの異なるセルスタイルしか必要としません。したがって、これらの2つをメソッドの外に 'cellStyle1'と' cellStyle2'として作成し、そのメソッドの中でどちらか一方のみを使用します。 –
どのようにそのエクセルの限界を超えて行くことができますか?そして何らかの理由で私は2つのスタイルを作成し、今度は16行目で終了します:D –
あなたはその優れた限界を越えることはできません。また、提供したメソッドの外に** 2つのセルスタイルを作成する必要があります。しかし、あなたが[最小限の、完全で、かつ証明可能な例](https://stackoverflow.com/help/mcve)を提供していないので、本当に良い答えはできません。 –