java - Apache POI Word XWPF 表方向和对齐方式

标签 java apache-poi xwpf

我想创建一个普通表格,并将其方向设置为“从右到左”“可以使用此选项设置Table Direction”,并使其对齐为“从左到右”,可以使用此选项设置Table Alignment

我已经尝试过这个:

XWPFTable myTable = myDocument.createTable();
CTTbl cttblp = myTable.getCTTbl();
CTTblPr cttblpr;
cttblpr = (cttblp.getTblPr() == null ? cttblp.addNewTblPr() : cttblp.getTblPr());

//table direction
cttblpr.addNewBidiVisual().setVal(STOnOff.ON);

//table alignment
CTJc ctjc = (cttblpr.isSetJc() ? cttblpr.getJc() : cttblpr.addNewJc());
ctjc.setVal(STJc.LEFT);

据我所知,表格方向的部分阻止了任何对齐的发生。

最佳答案

表格方向不会阻止对齐的发生,它会逆转对齐的影响。因此,在您的情况下,如果您将表格方向设置为从右到左,则必须将表格对齐方式设置为右,才能使其显示左对齐。对于具有左侧和右侧可视化的所有表格属性都是如此,例如左侧边框现在将显示在右侧,反之亦然。

参见ECMA-376 1st edition Part 4第2.4.23节第16行

If this property [jc (Table Alignment)] is omitted on a table, then the justification shall be determined by the associated table style. If this property is not specified in the style hierarchy, then the table shall be left justified with zero indentation from the leading margin (the left margin in a left-to-right table or the right margin in a right-to-left table).

ECMA-376 1st edition Part 4第 2.4.1 节第 7 行

When this property [bidiVisual (Visually Right to Left Table)] is specified, then the ordering of all cells (and table-level properties) in this table shall be applied to the table assuming that the table is a normal left to right table, but the table cells shall be displayed in a right to left direction. [Example: A left border on the first table cell shall be displayed on the right side of that cell (which would be the rightmost cell) in a visually right to left table. end example]

关于java - Apache POI Word XWPF 表方向和对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43964463/

相关文章:

java - Apache POI 评估公式

java - 使用 DirectoryChooser 保存文件时访问被拒绝

java - Hadoop ClassPath 单节点集群 Mac OS

java - 如何在 java 上使用诸如 PJSIP 之类的 C 库?

java - 为什么 Java 编译器(特别是它的解析器)不能理解这个语句

java - 如何使用 Apache POI 创建一个简单的 docx 文件?

java - 如果一个 String 是不可变的,那么为什么你必须调用一个方法来获取长度而不是仅仅访问一个变量,比如 array.length?

java - 尝试在工厂 org.apache.poi.xssf.usermodel.XSSFWorkbookFactory 和参数上调用 'createWorkbook' 时

java - Apache POI - 将 Word 文档 (docx) 拆分为页面

java - poi XWPF 双空格