Java Apache 然后居中对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38355440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:13:53 来源:igfitidea点击:
Apache poi center align
提问by
I am trying to align text. However, the text is not aligned.
我正在尝试对齐文本。但是,文本未对齐。
Cell lastCell = lastCell = row.createCell(cellNumber++);
if (value != null) {
lastCell.setCellValue(value);
}
CellStyle cellStyle = lastCell.getCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
lastCell.setCellStyle(cellStyle);
回答by
lastCell = row.createCell(cellNumber++);
CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
lastCell.setCellStyle(cellStyle);
if (number != null) {
lastCell.setCellValue(number);
}
Create a new cell style from workbook.
从工作簿创建新的单元格样式。
CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle();
回答by Gon_Com
You can replace:
您可以替换:
cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
with:
和:
cellStyle.setAlignment(HorizontalAlignment.RIGHT);