翻譯|使用教程|編輯:李顯亮|2021-05-17 10:06:25.830|閱讀 354 次
概述:本文將向您展示如何使用Spire.Doc for Java在Word上設置字符間距和段落間距。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for Java 是一款專業(yè)的Java Word組件,開發(fā)人員使用它可以輕松地將Word文檔創(chuàng)建、讀取、編輯、轉換和打印等功能集成到自己的Java應用程序中。
本文將向您展示如何使用Spire.Doc for Java在Word上設置字符間距和段落間距。可點擊此處下載最新版測試。
import com.spire.doc.*; import com.spire.doc.documents.Paragraph; import com.spire.doc.fields.TextRange; import java.awt.*; import java.io.*; public class setSpacing { public static void main(String[] args)throws IOException { //Load the sample document Document document= new Document("Sample1.docx"); //Add a new paragraph and append the text Paragraph para = new Paragraph(document); TextRange textRange1 = para.appendText("Newly added paragraph and set the paragraph spacing and character spacing"); textRange1.getCharacterFormat().setTextColor(Color.blue); textRange1.getCharacterFormat().setFontSize(14); //Set the spacing before and after paragraph para.getFormat().setBeforeAutoSpacing(false); para.getFormat().setBeforeSpacing(10); para.getFormat().setAfterAutoSpacing(false); para.getFormat().setAfterSpacing(10); //Set the character spacing for (DocumentObject object :(Iterable) para.getChildObjects()) { TextRange textRange= (TextRange) object; textRange.getCharacterFormat().setCharacterSpacing(3f); } //Insert the paragraph document.getSections().get(0).getParagraphs().insert(2, para); //Save the document to file document.saveToFile("Result.docx", FileFormat.Docx); } }
輸出結果
Spire.Doc for Java更新至v4.5.1,該版本支持驗證文檔的保護密碼,增強了Word到PDF/HTML/SVG的轉換功能,同時還修復了加載和合并文檔等時出現(xiàn)的問題。具體細節(jié)如下:
新功能:
Document document = new Document(); document.loadFromFile(input); boolean checkResult = document.checkProtectionPassWord(password);
String input="input.docx"; Document doc = new Document(); doc.loadFromFile(input); String result = "AddDigitalSignature.docx"; doc.saveToFile(result, FileFormat.Docx, "gary.pfx", "e-iceblue");
整合所有格式API處理套包Spire.office for Java正在慧都網(wǎng)火熱銷售中!立馬1分鐘了解全部咨詢!
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn