文檔金喜正規買球>>E-iceblue中文文檔>>設置 Word 頁邊距
設置 Word 頁邊距
Word Page Margins 可以看作是頁面邊緣和正文內容之間的距離。用戶經常調整頁邊距以使文檔正文適合頁面大小,以獲得最佳布局。本指南重點介紹一種解決方案,通過專業的 .NET Word 組件 Spire.Doc for .NET 在 C#、VB.NET 中輕松設置 Word 頁邊距。
Spire.Doc for .NET提供了一個PageSetup類,使用戶能夠在 Word 中獲取當前部分的頁面設置。自定義點和方向(縱向、橫向)的邊距(頂部、底部、左側和右側)屬性,以確保布局舒適和精彩。下面的截圖展示了設置 Word 的頁邊距后的結果。
技術交流Q群(767755948)
下載并安裝 Spire.Doc for .NET并按照步驟設置 Word 邊距。首先,獲取您想要設置加載文檔邊距的部分。其次,設置PageSetup的Margins屬性,包括Top、Bottom、Left和Right。第三,將 PageSetup 的 Orientation 屬性設置為 Landscape。代碼如下:
[C#]
using Spire.Doc; using Spire.Doc.Documents; namespace WordMargin { class Program { static void Main(string[] args) { //Load Document Document document = new Document(); document.LoadFromFile(@"E:\Work\Documents\WordDocuments\Valentine.docx"); //Set Margins document.Sections[0].PageSetup.Margins.Top = 17.9f; document.Sections[0].PageSetup.Margins.Bottom = 17.9f; document.Sections[0].PageSetup.Margins.Left = 17.9f; document.Sections[0].PageSetup.Margins.Right = 17.9f; //Set Page Orientation document.Sections[0].PageSetup.Orientation = PageOrientation.Landscape; //Save and Launch document.SaveToFile("WordMargin.docx", FileFormat.Docx2010); System.Diagnostics.Process.Start("WordMargin.docx"); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Doc.Documents Namespace WordMargin Friend Class Program Shared Sub Main(ByVal args() As String) 'Load Document Dim document As New Document() document.LoadFromFile("E:\Work\Documents\WordDocuments\Valentine.docx") 'Set Margins document.Sections(0).PageSetup.Margins.Top = 17.9F document.Sections(0).PageSetup.Margins.Bottom = 17.9F document.Sections(0).PageSetup.Margins.Left = 17.9F document.Sections(0).PageSetup.Margins.Right = 17.9F 'Set Page Orientation document.Sections(0).PageSetup.Orientation = PageOrientation.Landscape 'Save and Launch document.SaveToFile("WordMargin.docx", FileFormat.Docx2010) System.Diagnostics.Process.Start("WordMargin.docx") End Sub End Class End Namespace