文檔金喜正規買球>>Aspose.Cells開發者指南>>Excel管理控件Aspose.Cells開發者指南(三十五):設置頁面邊距
Excel管理控件Aspose.Cells開發者指南(三十五):設置頁面邊距
Aspose.Cells for .NET是Excel電子表格編程API,可加快電子表格管理和處理任務,支持構建具有生成,修改,轉換,呈現和打印電子表格功能的跨平臺應用程序。
在接下來的系列教程中,將為開發者帶來Aspose.Cells for .NET的一系列使用教程,例如關于加載保存轉換、字體、渲染、繪圖、智能標記等等。本文重點介紹如何設置頁面邊距。
>>Aspose.Cells for .NET已經更新至v20.7,添加FilterString()條件支持,支持對所有PivotField進行循環,提升Worksheet.Cells.RemoveDuplicates工作性能,發現4處異常情況,點擊下載體驗
第八章:關于頁面功能設置
▲第一節:設置邊距
頁邊距
使用PageSetup 類成員設置頁邊距(左,右,上,下)。下面列出了一些用于指定頁邊距的方法:
// The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create a workbook object Workbook workbook = new Workbook(); // Get the worksheets in the workbook WorksheetCollection worksheets = workbook.Worksheets; // Get the first (default) worksheet Worksheet worksheet = worksheets[0]; // Get the pagesetup object PageSetup pageSetup = worksheet.PageSetup; // Set bottom,left,right and top page margins pageSetup.BottomMargin = 2; pageSetup.LeftMargin = 1; pageSetup.RightMargin = 1; pageSetup.TopMargin = 3; // Save the Workbook. workbook.Save(dataDir + "SetMargins_out.xls");
頁面中心
可以在頁面上水平和垂直居中放置某些內容。為此,PageSetup 類有一些有用的成員CenterHorizontally 和CenterVertically。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create a workbook object Workbook workbook = new Workbook(); // Get the worksheets in the workbook WorksheetCollection worksheets = workbook.Worksheets; // Get the first (default) worksheet Worksheet worksheet = worksheets[0]; // Get the pagesetup object PageSetup pageSetup = worksheet.PageSetup; // Specify Center on page Horizontally and Vertically pageSetup.CenterHorizontally = true; pageSetup.CenterVertically = true; // Save the Workbook. workbook.Save(dataDir + "CenterOnPage_out.xls");
頁眉和頁腳邊距
使用PageSetup 類成員(例如HeaderMargin 和FooterMargin)設置頁眉和頁腳頁邊距。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create a workbook object Workbook workbook = new Workbook(); // Get the worksheets in the workbook WorksheetCollection worksheets = workbook.Worksheets; // Get the first (default) worksheet Worksheet worksheet = worksheets[0]; // Get the pagesetup object PageSetup pageSetup = worksheet.PageSetup; // Specify Header / Footer margins pageSetup.HeaderMargin = 2; pageSetup.FooterMargin = 2; // Save the Workbook. workbook.Save(dataDir + "CenterOnPage_out.xls");
還想要更多嗎?您可以點擊閱讀【2020 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術交流群(642018183),我們很高興為您提供查詢和咨詢。