利用Java設(shè)置Word文本框中的文字旋轉(zhuǎn)方向的實現(xiàn)方法
本次程序測試環(huán)境如下:
Word測試文檔版本:.docx 2013
Word Jar包工具:free spire.doc.jar 3.9.0
代碼編譯工具:IDEA
Jdk版本:1.8.0
導(dǎo)入操作文檔所需的jar包工具,如圖結(jié)果:
Java
import com.spire.doc.*;import com.spire.doc.documents.*;import com.spire.doc.fields.TextBox;import com.spire.doc.fields.TextRange;import java.awt.*;public class SetTextDirection { public static void main(String[] args) {//創(chuàng)建Word文檔Document doc = new Document();Section section = doc.addSection();//設(shè)置頁面邊距section.getPageSetup().getMargins().setLeft(90f);section.getPageSetup().getMargins().setRight(90f);Paragraph paragraph = section.addParagraph();//添加第一個文本框TextBox textBox1 = paragraph.appendTextBox(280, 250);//設(shè)置文本框為固定定位textBox1.getFormat().setHorizontalOrigin(HorizontalOrigin.Page);textBox1.getFormat().setHorizontalPosition(150);textBox1.getFormat().setVerticalOrigin(VerticalOrigin.Page);textBox1.getFormat().setVerticalPosition(80);//設(shè)置文字旋轉(zhuǎn)方向textBox1.getFormat().setTextAnchor(ShapeVerticalAlignment.Center);textBox1.getFormat().setLayoutFlowAlt(TextDirection.Left_To_Right);//旋轉(zhuǎn)文字(逆時針)//textBox1.getFormat().setLayoutFlowAlt(TextDirection.Left_To_Right_Rotated);//文字豎排顯示//添加文字并設(shè)置字體Paragraph textboxPara1 = textBox1.getBody().addParagraph();TextRange txtrg = textboxPara1.appendText('姓名_______學(xué)號_________班級__________');txtrg.getCharacterFormat().setFontName('等線');txtrg.getCharacterFormat().setFontSize(10);txtrg.getCharacterFormat().setTextColor(Color.black);textboxPara1.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);//保存文檔doc.saveToFile('Result.docx');doc.dispose(); }}
執(zhí)行程序后,生成Word文檔,打開該文檔后可查看文本框中的文字旋轉(zhuǎn)效果。通過設(shè)置不同旋轉(zhuǎn)效果,可查看文本框中的文字效果,如圖:
Left_To_Right旋轉(zhuǎn)效果:
Left_To_Right_Rotated豎排顯示效果:
延伸閱讀:
C# 設(shè)置Word文本框中的文字旋轉(zhuǎn)方向
到此這篇關(guān)于利用Java設(shè)置Word文本框中的文字旋轉(zhuǎn)方向的實現(xiàn)方法的文章就介紹到這了,更多相關(guān)Java設(shè)置Word文本框中的文字旋轉(zhuǎn)方向內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章: