有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Apache POI Word 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);

据我所知,工作台方向的一部分会阻止任何对齐


共 (1) 个答案

  1. # 1 楼答案

    表格方向不会阻止对齐,它会反转对齐的影响。因此,在本例中,如果将表方向设置为Right-to-Left,则必须将表对齐设置为Right,以便显示左对齐。这适用于所有具有左右可视化的表属性,例如,左边框现在将显示在右侧,反之亦然

    见第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]