翻譯|使用教程|編輯:胡濤|2022-05-10 10:11:09.330|閱讀 422 次
概述:本文介紹了如何使用Spire.Doc for .NET以編程方式在 Word 文檔中設置段落縮進,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在 Word 文檔中,縮進是一種段落格式,用于調整段落正文和頁邊距之間的距離。它包括左縮進、右縮進、首行縮進和懸掛縮進。左縮進和右縮進可以應用于段落的所有行,而首行縮進只能應用于段落的第一行。至于懸掛縮進,它可以應用于除第一行之外的段落的每一行。本文介紹了如何使用Spire.Doc for .NET以編程方式在 Word 文檔中設置段落縮進
首先,您需要添加 Spire.Doc for .NET 包中包含的 DLL 文件作為 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
下表列出了一些用于在 Word 文檔中設置不同段落縮進的核心類和屬性。
姓名 | 描述 |
段落格式類 | 表示段落的格式。 |
ParagraphFormat.LeftIndent 屬性 | 返回或設置表示段落左縮進的值。 |
ParagraphFormat.RightIndent 屬性 | 返回或設置表示段落右縮進的值。 |
ParagraphFormat.FirstLineIndent 屬性 | 獲取或設置第一行或懸掛縮進的值。正值代表首行縮進,負值代表懸掛縮進。 |
詳細步驟如下:
【C#】
using Spire.Doc; using Spire.Doc.Documents; namespace WordIndent { class Program { static void Main(string[] args) { //Create a Document instance Document doc = new Document(); //Load a sample Word document doc.LoadFromFile("sample.docx"); //Get the first paragraph and set left indent Paragraph para1 = doc.Sections[0].Paragraphs[0]; para1.Format.LeftIndent = 30; //Get the second paragraph and set right indent Paragraph para2 = doc.Sections[0].Paragraphs[1]; para2.Format.RightIndent = 30; //Get the third paragraph and set first line indent Paragraph para3 = doc.Sections[0].Paragraphs[2]; para3.Format.FirstLineIndent = 30; //Get the fourth paragraph and set hanging indent Paragraph para4 = doc.Sections[0].Paragraphs[3]; para4.Format.FirstLineIndent = -30; //Save the document to file doc.SaveToFile("Indent.docx", FileFormat.Docx2010); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Namespace WordIndent Friend Class Program Shared Sub Main(ByVal args() As String) 'Create a Document instance Dim doc As New Document() 'Load a sample Word document doc.LoadFromFile("sample.docx") 'Get the first paragraph and set left indent Dim para1 As Paragraph = doc.Sections(0).Paragraphs(0) para1.Format.LeftIndent = 30 'Get the second paragraph and set right indent Dim para2 As Paragraph = doc.Sections(0).Paragraphs(1) para2.Format.RightIndent = 30 'Get the third paragraph and set first line indent Dim para3 As Paragraph = doc.Sections(0).Paragraphs(2) para3.Format.FirstLineIndent = 30 'Get the fourth paragraph and set hanging indent Dim para4 As Paragraph = doc.Sections(0).Paragraphs(3) para4.Format.FirstLineIndent = -30 'Save the document to file doc.SaveToFile("Indent.docx", FileFormat.Docx2010) End Sub End Class End Namespace
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn