设置边距

设置边距

Aspose.Cells提供了一个类,工作簿 , 表示一个 Excel 文件。这工作簿类包含工作表允许访问 Excel 文件中每个工作表的集合。工作表由工作表班级。

工作表类提供了页面设置用于设置工作表页面设置选项的属性。这页面设置属性是一个对象页面设置使开发人员能够为打印的工作表设置不同页面布局选项的类。这页面设置类提供用于设置页面设置选项的各种属性和方法。

页边距

使用设置页边距(左、右、上、下)页面设置班级成员。下面列出了一些用于指定页边距的方法:

// 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");

页面居中

可以在页面上水平和垂直居中某些内容。为此,有一些有用的成员页面设置班级,水平居中垂直居中.

// 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");

页眉和页脚边距

设置页眉和页脚边距页面设置班级成员如页眉边距页脚边距.

// 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 Header / Footer margins
pageSetup.HeaderMargin = 2;
pageSetup.FooterMargin = 2;
// Save the Workbook.
workbook.Save(dataDir + "CenterOnPage_out.xls");