该文将详细介绍在保存Excel工作簿到PDF文档时,在 PDF 结果文档中添加页码。
C#
using Spire.Xls;
namespace ExcelDemo
{
class Program
{
static void Main(string[] args)
{
//加载示例文档
Workbook wbk = new Workbook();
wbk.LoadFromFile("Sample.xlsx");
foreach (Worksheet sheet in wbk.Worksheets)
{
//&P 指Page Number, &N 指总页数
sheet.PageSetup.RightFooter = "&P/&N";
}
//保存文档
wbk.SaveToFile("Result.pdf", FileFormat.PDF);
}
}
}
VB.NET
Imports Spire.Xls
Namespace ExcelDemo
Class Program
Private Shared Sub Main(ByVal args() As String)
'加载示例文档
Dim wbk As Workbook = New Workbook
wbk.LoadFromFile("Sample.xlsx")
For Each sheet As Worksheet In wbk.Worksheets
'&P 指Page Number, &N 指总页数
sheet.PageSetup.RightFooter = "&P/&N"
Next
'保存文档
wbk.SaveToFile("Result.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace
效果图: