翻譯|使用教程|編輯:胡濤|2022-06-13 11:27:15.967|閱讀 308 次
概述:本文介紹如何在 C#、VB.NET 中設置 Word 頁邊距,歡迎下載試用!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Word Page Margins 可以看作是頁面邊緣和正文內容之間的距離。用戶經常調整頁邊距以使文檔正文適合頁面大小,以獲得最佳布局。本指南重點介紹一種解決方案,通過專業的 .NET Word 組件 Spire.Doc for .NET 在 C#、VB.NET 中輕松設置 Word 頁邊距。
Spire.Doc for .NET提供了一個PageSetup類,使用戶能夠在 Word 中獲取當前部分的頁面設置。自定義點和方向(縱向、橫向)的邊距(頂部、底部、左側和右側)屬性,以確保布局舒適和精彩。下面的截圖展示了設置 Word 的頁邊距后的結果。
下載并安裝 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
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn