using IronXL;
using IronXL.Printing;
WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Set the print header and footer of the worksheet
workSheet.Header.Center = "My document";
workSheet.Footer.Center = "Page &P of &N";
// Set the header margin
workSheet.PrintSetup.HeaderMargin = 2.33;
// Set the size of the paper
// Paper size enum represents different sizes of paper
workSheet.PrintSetup.PaperSize = PaperSize.B4;
// Set the print orientation of the worksheet
workSheet.PrintSetup.PrintOrientation = PrintOrientation.Portrait;
// Set black and white printing
workSheet.PrintSetup.NoColor = true;
workBook.SaveAs("PrintSetup.xlsx");
Imports IronXL
Imports IronXL.Printing
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Set the print header and footer of the worksheet
workSheet.Header.Center = "My document"
workSheet.Footer.Center = "Page &P of &N"
' Set the header margin
workSheet.PrintSetup.HeaderMargin = 2.33
' Set the size of the paper
' Paper size enum represents different sizes of paper
workSheet.PrintSetup.PaperSize = PaperSize.B4
' Set the print orientation of the worksheet
workSheet.PrintSetup.PrintOrientation = PrintOrientation.Portrait
' Set black and white printing
workSheet.PrintSetup.NoColor = True
workBook.SaveAs("PrintSetup.xlsx")
Install-Package IronXL.Excel
Excel 打印设置
IronXL 允许以编程方式为任何 Excel 文档定义打印设置。对文档如何在物理或 PDF 打印机上打印的各种设置进行细粒度控制。
还可以设置文档页眉和页脚,包括 "邮件合并 "变量的功能:
&P`:页码
&N: 总页数
&D: 当前日期
&T: 当前时间
&Z&F: 文件路径
&F: 文件名称
&A: 工作表名称
这些变量可直接用于设置为 Footer 属性的字符串中。例如,要在所有打印页面的底部显示页码,可设置 workSheet.Footer.Center = "Page &P of &N"。