Apache poi Apache POI excel如何为单元格应用文本左上缩进

Apache poi Apache POI excel如何为单元格应用文本左上缩进,apache-poi,alignment,indentation,Apache Poi,Alignment,Indentation,如何在ApachePOI中添加具有左文本对齐的左上缩进 我目前拥有的: private CellStyle setDateAndTimeCellStyle(XSSFWorkbook workbook, Font font) { CellStyle dateCellStyle = workbook.createCellStyle(); dateCellStyle.setWrapText(true); dateCellStyle.setAlignment(CellStyl

如何在ApachePOI中添加具有左文本对齐的左上缩进

我目前拥有的:

 private CellStyle setDateAndTimeCellStyle(XSSFWorkbook workbook, Font font) {

    CellStyle dateCellStyle = workbook.createCellStyle();
    dateCellStyle.setWrapText(true);
    dateCellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    dateCellStyle.setIndention(CellStyle.VERTICAL_TOP);
    dateCellStyle.setFont(font);
    dateCellStyle.setBorderTop(CellStyle.BORDER_THIN);
    dateCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    dateCellStyle.setBorderRight(CellStyle.BORDER_THIN);
    return dateCellStyle;
}

CellStyle dateCellStyle = setDateAndTimeCellStyle(workbook, font);

您使用的是什么古老的
apachepoi
版本?
CellStyle
中的常量已在版本
3.17
中删除。当前版本为
4.1.1
。和
CellStyle.setIndention(短缩进)
从来没有使用常量,而是设置单元格中文本缩进的空格数。参数
indent
给出从左侧缩进的空格数。据我所知,从顶部缩进是不可能的。您将如何在
Excel
GUI
中执行此操作?我使用的是3.0.2版。Excel GUI中有一个选项可以将缩进设置为顶部、中心或底部。有什么办法可以做到这一点吗?Whow版本
3.0.2
。您还在使用Windows 3.11,是吗?但由于版本
3.0.2
甚至没有类
CellStyle
,我对此表示怀疑。我猜你指的是垂直对齐而不是缩进:
CellStyle.setVerticalAlignment(CellStyle.vertical\u TOP)
CellStyle.setVerticalAlignment(CellStyle.VERTICAL\u中心)
CellStyle.setVerticalAlignment(CellStyle.VERTICAL\u底部)
单元样式。设置垂直对齐(单元样式。垂直对齐)
.Correction,版本为4.0.1In
ApachePOI4.0.1
您显示的代码无法编译。不再有
CellStyle.VERTICAL.*
常量。有一个参数作为align参数。