利用Java設(shè)置Word文本框中的文字旋轉(zhuǎn)方向的實現(xiàn)方法
Java設(shè)置Word文本框中的文字旋轉(zhuǎ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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java+mysql模擬實現(xiàn)銀行系統(tǒng)
這篇文章主要為大家詳細介紹了java+mysql模擬實現(xiàn)銀行系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-05-05Springboot居然可以設(shè)置動態(tài)的Banner(推薦)
這篇文章主要介紹了Springboot居然可以設(shè)置動態(tài)的Banner,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03Java實戰(zhàn)寵物醫(yī)院預(yù)約掛號系統(tǒng)的實現(xiàn)流程
只學(xué)書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+JSP+Spring+SpringBoot+MyBatis+html+layui+maven+Mysql實現(xiàn)一個寵物醫(yī)院預(yù)約掛號系統(tǒng),大家可以在過程中查缺補漏,提升水平2022-01-01