• <menu id="w2i4a"></menu>
  • logo E-iceblue中文文檔

    文檔首頁>>E-iceblue中文文檔>>在 Word 中對齊文本

    在 Word 中對齊文本


    Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。 

    E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式

    Spire.Doc for.NET 最新下載

    文本對齊是一個段落格式屬性,它決定了整個段落中文本的外觀。Microsoft Word 中有四種可用的文本對齊方式:左對齊、居中對齊、右對齊和兩端對齊。在本文中,您將學(xué)習(xí)如何使用Spire.Doc for .NET以編程方式為 Word 文檔中的段落設(shè)置不同的文本對齊方式。

    為 .NET 安裝 Spire.Doc

    首先,您需要添加 Spire.Doc for .NET 包中包含的 DLL 文件作為 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。

    PM> Install-Package Spire.Doc
    在 Word 中對齊文本
    • 創(chuàng)建一個文檔實例。
    • 使用Document.LoadFromFile()方法加載示例 Word 文檔。
    • 使用Document.Section[]屬性獲取指定部分。
    • 使用Section.Paragraphs[]屬性獲取指定段落。
    • 使用Paragraph.Format屬性獲取段落格式
    • 使用ParagraphFormat.HorizontalAlignment屬性設(shè)置指定段落的文本對齊方式。
    • 使用Document.SaveToFile()方法將文檔保存到另一個文件。

    [C#]

    using Spire.Doc;
    using Spire.Doc.Documents;
    
    namespace AlignText
    {
    class Program
    {
    static void Main(string[] args)
    {
    //Create a Document instance
    Document doc = new Document();
    
    //Load a sample Word document
    doc.LoadFromFile(@"D:\Files\sample.docx");
    
    //Get the first section
    Section section = doc.Sections[0];
    
    //Get the first paragraph and make it center-aligned
    Paragraph p = section.Paragraphs[0];
    p.Format.HorizontalAlignment = HorizontalAlignment.Center;
    
    //Get the second paragraph and make it left-aligned
    Paragraph p1 = section.Paragraphs[1];
    p1.Format.HorizontalAlignment = HorizontalAlignment.Left;
    
    //Get the third paragraph and make it right-aligned
    Paragraph p2 = section.Paragraphs[2];
    p2.Format.HorizontalAlignment = HorizontalAlignment.Right;
    
    //Get the fourth paragraph and make it justified
    Paragraph p3 = section.Paragraphs[3];
    p3.Format.HorizontalAlignment = HorizontalAlignment.Justify;
    
    //Save the document
    doc.SaveToFile("WordAlignment.docx", FileFormat.Docx);
    }
    }
    }

    [VB.NET]

    Imports Spire.Doc
    Imports Spire.Doc.Documents
    
    Namespace AlignText
    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("E:\Work\Documents\WordDocuments\Humor Them.docx")
    
    'Get the first section
    Dim section As Section = doc.Sections(0)
    
    'Get the first paragraph and make it center-aligned
    Dim p As Paragraph = section.Paragraphs(0)
    p.Format.HorizontalAlignment = HorizontalAlignment.Center
    
    'Get the second paragraph and make it left-aligned
    Dim p1 As Paragraph = section.Paragraphs(1)
    p1.Format.HorizontalAlignment = HorizontalAlignment.Left
    
    'Get the third paragraph and make it right-aligned
    Dim p2 As Paragraph = section.Paragraphs(2)
    p2.Format.HorizontalAlignment = HorizontalAlignment.Right
    
    'Get the fourth paragraph and make it justified
    Dim p3 As Paragraph = section.Paragraphs(3)
    p3.Format.HorizontalAlignment = HorizontalAlignment.Justify
    
    'Save the document
    doc.SaveToFile("WordAlignment.docx", FileFormat.Docx)
    End Sub
    End Class
    End Namespace

    C#/VB.NET:在 Word 中對齊文本


    歡迎下載|體驗更多E-iceblue產(chǎn)品

    獲取更多信息請咨詢慧都在線客服  ;技術(shù)交流Q群(767755948)


    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();