简体   繁体   English

如何更改XWPFDocument中的文本方向?

[英]How can i change text orientation in XWPFDocument?

I am working right now in producing word documents in java and i am using XWPFDocument of POI Apache. 我正在使用Java生成Word文档,现在正在使用POI Apache的XWPFDocument。 The final document must looks like this 最终文件必须如下所示

http://sk.uploads.im/t/rtwvm.png http://sk.uploads.im/t/rtwvm.png

till no everything works fine, I created table, managed to merge cells but i can not find a way to change the text orientation in table cells. 直到一切正常,我创建了表格,设法合并了单元格,但是我找不到改变表格单元格中文本方向的方法。 I simply want "Type 1" to be upward. 我只是希望“类型1”向上。 I only found a solution using cellStyle which seems to work only in excel and not in word, which i am using. 我只找到了一个使用cellStyle的解决方案,该解决方案似乎只能在Excel中使用,而不能在我正在使用的单词中使用。

You probably need to create two documents in Word, one with the normal orientation and one with the changed one, then unzip them (.docx is actually a Zip-File) and analyze which xml-structure is responsible for this. 您可能需要在Word中创建两个文档,一个文档的方向正常,而另一个文档的方向已更改,然后解压缩它们(.docx实际上是一个Zip文件),并分析造成该问题的xml结构。

Then you can check if POI already offers higher level APIs for these or if you need to access the low-level POI classes via the getCTxxx() methods, eg XWPFTableCell.getCTTc() returns the underlying XML structure and allows you to do things that are not possible via the normal POI interfaces. 然后,您可以检查POI是否已经为它们提供了更高级别的API,或者是否需要通过getCTxxx()方法访问低级POI类,例如XWPFTableCell.getCTTc()返回底层XML结构并允许您执行以下操作通过普通的POI接口是不可能的。

You can use something like: cell.getCTTc().getTcPr().addNewTextDirection().setVal(STTextDirection.BT_LR) , where the parameters are found in: STTextDirection . 您可以使用诸如cell.getCTTc().getTcPr().addNewTextDirection().setVal(STTextDirection.BT_LR)之类的参数,这些参数位于: STTextDirection中

The problem I couldn't solve yet is that the row height does not update automatically to the vertical text length, then the text is not completely showed. 我无法解决的问题是行高不会自动更新为垂直文本长度,因此文本无法完全显示。 If you solve it, please, post here. 如果您解决了该问题,请在此处发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM