设置打印选项
Contents
[
Hide
]
Microsoft Excel 的页面设置设置提供了多个打印选项(也称为工作表选项),允许用户控制工作表页面的打印方式。
设置打印选项
这些打印选项允许用户:
- 选择工作表上的特定打印区域。
- 打印标题。
- 打印网格线。
- 打印行/列标题。
- 达到草稿质量。
- 打印评论。
- 打印单元错误。
- 定义页面排序。
Aspose.Cells 支持 Microsoft Excel 提供的所有打印选项,开发人员可以使用 Excel 提供的属性轻松地为工作表配置这些选项页面设置班级。下面将更详细地讨论如何使用这些属性。
设置打印区域
默认情况下,打印区域包含工作表中包含数据的所有区域。开发人员可以建立工作表的特定打印区域。
要选择特定的打印区域,请使用页面设置班级'打印区域财产。将定义打印区域的单元格范围分配给此属性。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the PageSetup of the worksheet | |
PageSetup pageSetup = workbook.Worksheets[0].PageSetup; | |
// Specifying the cells range (from A1 cell to T35 cell) of the print area | |
pageSetup.PrintArea = "A1:T35"; | |
// Save the workbook. | |
workbook.Save(dataDir + "SetPrintArea_out.xls"); |
设置打印标题
Aspose.Cells 允许您指定行和列标题以在打印的工作表的所有页面上重复。为此,请使用页面设置班级'打印标题列和打印标题行特性。
将重复的行或列通过传递它们的行号或列号来定义。例如,行定义为 $1:$2,列定义为 $A:$B。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the PageSetup of the worksheet | |
Aspose.Cells.PageSetup pageSetup = workbook.Worksheets[0].PageSetup; | |
// Defining column numbers A & B as title columns | |
pageSetup.PrintTitleColumns = "$A:$B"; | |
// Defining row numbers 1 & 2 as title rows | |
pageSetup.PrintTitleRows = "$1:$2"; | |
// Save the workbook. | |
workbook.Save(dataDir + "SetPrintTitle_out.xls"); |
设置其他打印选项
这页面设置类还提供了几个其他属性来设置常规打印选项,如下所示:
- 打印网格线一个布尔属性,定义是否打印网格线。
- 打印标题定义是否打印行和列标题的布尔属性。
- 黑与白:一个布尔属性,定义是否以黑白模式打印工作表。
- 打印评论:定义是在工作表上还是在工作表末尾显示打印注释。
- 打印草稿一个布尔属性,定义是否打印没有图形的工作表。
- 打印错误: 定义是否将单元格错误打印为显示、空白、破折号或 N/A。
设置打印评论和打印错误属性,Aspose.Cells还提供了两个枚举,打印注释类型 , 和打印错误类型包含要分配给的预定义值打印评论和打印错误分别属性。
中的预定义值打印注释类型下面列出了枚举及其描述。
打印注释类型 | 描述 |
---|---|
就地打印 | 指定打印工作表上显示的注释。 |
打印无评论 | 指定不打印注释。 |
打印页结束 | 指定在工作表末尾打印注释。 |
的预定义值打印错误类型下面列出了枚举及其描述。
打印错误类型 | 描述 |
---|---|
打印错误空白 | 指定不打印错误。 |
PrintErrorsDash | 指定将错误打印为“–”。 |
显示打印错误 | 指定打印显示的错误。 |
打印错误NA | 指定将错误打印为“#N/A”。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the PageSetup of the worksheet | |
PageSetup pageSetup = workbook.Worksheets[0].PageSetup; | |
// Allowing to print gridlines | |
pageSetup.PrintGridlines = true; | |
// Allowing to print row/column headings | |
pageSetup.PrintHeadings = true; | |
// Allowing to print worksheet in black & white mode | |
pageSetup.BlackAndWhite = true; | |
// Allowing to print comments as displayed on worksheet | |
pageSetup.PrintComments = PrintCommentsType.PrintInPlace; | |
// Allowing to print worksheet with draft quality | |
pageSetup.PrintDraft = true; | |
// Allowing to print cell errors as N/A | |
pageSetup.PrintErrors = PrintErrorsType.PrintErrorsNA; | |
// Save the workbook. | |
workbook.Save(dataDir + "OtherPrintOptions_out.xls"); |
设置页面顺序
这页面设置类提供了命令用于订购要打印的工作表的多页的属性。有两种可能性可以按如下方式对页面进行排序。
- **下来然后结束:**在向右打印任何页面之前先向下打印所有页面。
- **然后向下:**在打印下面的页面之前先从左到右打印页面。
Aspose.Cells 提供枚举,打印订单类型包含所有预定义的订单类型。
的预定义值打印订单类型列举如下。
打印订单类型 | 描述 |
---|---|
先下后上 | 将打印顺序表示为向下然后结束。 |
过后 | 表示打印顺序为 over 然后 down。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the PageSetup of the worksheet | |
PageSetup pageSetup = workbook.Worksheets[0].PageSetup; | |
// Setting the printing order of the pages to over then down | |
pageSetup.Order = PrintOrderType.OverThenDown; | |
// Save the workbook. | |
workbook.Save(dataDir + "SetPageOrder_out.xls"); |