How to get the page count of excel file in C#

Different printer drivers print out the document with different numbers of rows and columns. When we need to print an excel file with header and footer, the information of how many pages in one excel file and where is the first line start becomes very important. This article will show you how to get the page count of excel file and the row and column number of page break in C# by using Spire.XLS for .NET.

Firstly, make sure that Spire.XLS for .NET (version7.3.12 or above) has been installed on your machine. And then, adds Spire.XLS.dll as reference in the downloaded Bin folder thought the below path: "..\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll".

Now it comes to the details of how to get the page count of excel file in C#:

//Create a new excel document
Workbook wb = new Workbook();
//load from the file
wb.LoadFromFile(@"D:\test.xlsx");
//get the page info.
var pageInfoList = wb.GetSplitPageInfo();
//Get the sheet count
int sheetCount = pageInfoList.Count;
//The page count of the first sheet
int pageCount = pageInfoList[0].Count;

You could find a screenshot shows row number and column number of each Excel page.

Get the page count of excel file

Spire.XLS for .NET, as a professional Excel component, it enables you to generate, read, write and manipulate Excel files in C#, VB.NET in any .NET applications directly.