I used POI
and tried to arrange one entire column. But only the way I found is arrange individual cell. Although I found sheet.setDefaultColumnStyle()
and tried to use this function, it doesn't work at all.
could you let me know the way of using setDefaultColumnStyle()
or another way.
below code is my code to arrange individual cell.
xlsxFile = new File("data.xlsx");
wb = new XSSFWorkbook();
cellStyle = wb.createCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
row = sheet1.createRow(0);
cell = row.createCell(1);
cell.setCellValue("name");
cell.setCellStyle(cellStyle);
My english skill is a little awkward. Thank you for reading. If there is anything weird, please let me know.
This seems to be an bug in Apache POI. There are two issues:
First: After using
Sheet.setDefaultColumnStyle
with a style which defines alignments, POI does not setapplyAlignment="true"
in thexf
element's tag instyles.xml
. But it should, because only that will cause Excel to apply the alignments from that style to new cells.Second: POI itself does not apply this style to new cells in that column. It should set
s="1"
, where 1 is the style number, in the correspondingc
tag ofSheet1.xml
.So we have to workaround: