数値の列データをフォーマットしようとしています。以下は、単一セルで機能するコードです。
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the added worksheet in the Excel file
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
//Adding the current system date to "A1" cell
Cell cell = cells.get("A1");
cell.setValue(Calendar.getInstance());
//Setting the display format of the date to number 15 to show date as "d-mmm-yy"
Style style = cell.getStyle();
style.setCustom("d-mmm-yy");
cell.setStyle(style);
//Adding a numeric value to "A2" cell
cell = cells.get("A2");
cell.setValue(20);
//Setting the display format of the value to number 9 to show value as percentage
style = cell.getStyle();
style.setCustom("0.0%");
cell.setStyle(style);
//Adding a numeric value to "A3" cell
cell = cells.get("A3");
cell.setValue(1546);
//Setting the display format of the value to number 6 to show value as currency
style = cell.getStyle();
style.setCustom("$#,##0;[Red]$-#,##0");
cell.setStyle(style);
//Saving the modified Excel file in default format
workbook.save("C:\\output.xls");
これが列のコードです。以下のコードは機能していません:(
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the added worksheet in the Excel file
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
Column column = cells.getColumns().get(30);
Style style =column.getStyle();
style.setHorizontalAlignment(TextAlignmentType.CENTER);
style.setCustom("$#,##0;[Red]$-#,##0");
StyleFlag styleFlag = new StyleFlag();
//Applying the style to the column
column.applyStyle(style, styleFlag);
//Saving the modified Excel file in default format
workbook.save("C:\\output.xls");
誰でもこれを手伝ってもらえますか。