Split worksheets into pages

In case you want to achieve better experience in viewing large Excel worksheets you can split worksheets into pages instead of rendering the whole worksheet. There are two options here that are shown in the image below.

Split worksheets into pages

Each option may be a better choice depending on how many rows and columns your spreadsheets have. When a spreadsheet has a lot of columns it is preferable to split worksheet by rows and columns.

How to split worksheet by rows only

By default, we’re splitting worksheets by rows only. The default “rows per page” value is 40. So, when you have a workbook with a single worksheet with 100 rows you’ll get three pages where the first page will contain the first 40 rows, the second page next 40 rows, and the third page the last 20 rows.

In the next example, we’ll split the worksheet into two pages. We’ll be using this sample file and the following code:

using (Viewer viewer = new Viewer("two-pages.xlsx"))
{
    int countRowsPerPage = 15;

    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewOptions.SpreadsheetOptions = SpreadsheetOptions.ForSplitSheetIntoPages(countRowsPerPage);

    viewer.View(viewOptions);
}

The following screenshot shows two output pages.

Output HTML two pages

How to split worksheet by rows and columns

Now, let’s use this sample file and split worksheet by rows and columns.

using (Viewer viewer = new Viewer("four-pages.xlsx"))
{
    int countRowsPerPage = 15;
    int countColumnsPerPage = 7;

    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewOptions.SpreadsheetOptions = SpreadsheetOptions.ForSplitSheetIntoPages(countRowsPerPage, countColumnsPerPage);

    viewer.View(viewOptions);
}

After executing the code above we’ll get four pages on the output.

Output HTML four pages

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.