设置边距
设置页边距
Aspose.Cells 提供一个名为 Workbook 的类,它表示 Excel 文件。Workbook 类包含允许访问 Excel 文件中每个工作表的 Worksheets 集合。工作表由 Worksheet 类表示。
Worksheet类提供了PageSetup属性,用于设置工作表的页面设置选项。PageSetup属性是PageSetup类的一个对象,使开发人员能够为打印的工作表设置不同的页面布局选项。PageSetup类提供了用于设置页面设置选项的各种属性和方法。
页面边距
使用PageSetup类的成员设置页面边距(左、右、上、下)。下面列出了一些用于指定页面边距的方法:
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// 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。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// 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)设置页眉和页脚边距。