gpt4 book ai didi

java - XWPFTable 中的文本方向

转载 作者:行者123 更新时间:2023-12-01 17:58:12 24 4
gpt4 key购买 nike

如何在 XWPFTable 中使用 Apache POI 将文本旋转到 90 度?

So it will look like this

最佳答案

到目前为止,文本方向设置尚未实现到 XWPFTableCell 中。但使用getCTTc我们可以得到底层CTTc目的。由此我们可以设置 addNewTcPr() , addNewTextDirection() .

为了使用org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTextDirection,此示例需要所有模式的完整 jar ooxml-schemas-1.3.jarFAQ-N10025 中所述.

示例:

import java.io.File;
import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextDirection;

public class CreateWordTableTextVertical {
public static void main(String[] args) throws Exception {

XWPFDocument document = new XWPFDocument();

XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("The table:");

XWPFTable table = document.createTable(1,3);
for (int r = 0; r < 1; r++) {
for (int c = 0 ; c < 3; c++) {
XWPFTableCell tableCell = table.getRow(r).getCell(c);
tableCell.getCTTc().addNewTcPr().addNewTextDirection().setVal(STTextDirection.BT_LR);
paragraph = tableCell.getParagraphArray(0);
run = paragraph.createRun();
run.setText("text");
}
}

paragraph = document.createParagraph();

document.write(new FileOutputStream("CreateWordTableTextVertical.docx"));
document.close();

}
}

关于java - XWPFTable 中的文本方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43010096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com