sah*_*ngh 21 apache apache-poi
我正在使用POI api.现在我的问题是我无法将单元格文本垂直对齐顶部.我正在使用getCellStyle().setAlignment(HSSFCellStyle.VERTICAL_TOP)设置对齐方式.
然而,当我打开表格时,它没有受到影响.
Vla*_*lad 26
也有这个问题,你会被贬低,但是要在POI中设置垂直对齐样式,你应该使用setVerticalAlignment()函数setAlignment().例:
XSSFCellStyle styleSubHeader = (XSSFCellStyle) wb.createCellStyle();
styleSubHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
Run Code Online (Sandbox Code Playgroud)
Jes*_*hez 10
您可以使用此代码:
style.setVerticalAlignment(VerticalAlignment.TOP);
Run Code Online (Sandbox Code Playgroud)
XSSFWorkbook wbOut = new XSSFWorkbook();
CellStyle style = wbOut.createCellStyle();
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cell.setCellStyle(style);
Run Code Online (Sandbox Code Playgroud)
这个实现
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP)
Run Code Online (Sandbox Code Playgroud)
已弃用,请使用:
org.apache.poi.ss.usermodel.CellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
Run Code Online (Sandbox Code Playgroud)
小智 -4
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
cell = row.createCell((short) 2);
cell.setCellValue("X");
cell.setCellStyle(style);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39455 次 |
| 最近记录: |