XWPFTable中的文字方向 [英] Text direction in XWPFTable

查看:196
本文介绍了XWPFTable中的文字方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to rotate text using Apache POI in XWPFTable to 90 degrees?

看起来像这样

推荐答案

到目前为止,文本方向设置尚未在XWPFTableCell中实现.但是使用 getCTTc 我们可以获取底层 CTTc 对象.然后我们可以设置

The text direction settings are not implemented into XWPFTableCell until now. But using getCTTc we can get the underlaying CTTc object. And from this we can set addNewTcPr(), addNewTextDirection().

要使用org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTextDirection,此示例需要ooxml-schemas-1.3.jar的完整jar. ="nofollow noreferrer"> FAQ-N10025 .

For using org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTextDirection this example needs the full jar of all of the schemas ooxml-schemas-1.3.jar as mentioned in the FAQ-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();

 }
}

这篇关于XWPFTable中的文字方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆