Partial rendering of Large Excel Spreadsheets

There is a blog post saying that this is possible from version 17 onwards. But I cannot find an option to limit the size of the spreadsheet being rendered. I tried just choosing x columns and x rows, but that just splits them on to separate pages.

Is there in fact a way to limit how many rows are rendered per sheet?

Partially Render Large Excel Sheets with GroupDocs.Viewer for .NET 17.1.0

@Anf93

Unfortunately, it can’t be done with GroupDocs.Viewer for .NET 17.1. Please check this sample-app.zip (39.4 KB) that is using the latest version of GroupDocs.Viewer and renders N rows of each worksheet see output.zip (19.0 KB). Let me also share the code:

using System;
using System.Collections.Generic;
using System.Linq;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
using GroupDocs.Viewer.Results;

namespace partial_rendering
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            SetLicense();
            RenderFirstNRowsOfEachWorksheet("sample.xlsx", 10);
        }

        private static void RenderFirstNRowsOfEachWorksheet(string filePath, int countOfRows)
        {
            using (var viewer = new Viewer(filePath))
            {
                var viewOptions =
                    HtmlViewOptions.ForEmbeddedResources();
                viewOptions.SpreadsheetOptions =
                    SpreadsheetOptions.ForSplitSheetIntoPages(countRowsPerPage: countOfRows);

                var viewInfoOptions =
                    ViewInfoOptions.FromHtmlViewOptions(viewOptions);

                var viewInfo = viewer.GetViewInfo(viewInfoOptions);

                // Get all the pages that have different name 
                Console.WriteLine("All the pages:");
                foreach (var page in viewInfo.Pages)
                    Console.WriteLine(page);

                var pagesToRender = new List<Page>
                {
                    viewInfo.Pages.First()
                };

                foreach (var page in viewInfo.Pages)
                {
                    if (pagesToRender.All(p => p.Name != page.Name))
                        pagesToRender.Add(page);
                }

                Console.WriteLine("\nPages to render:");
                foreach (var page in pagesToRender)
                    Console.WriteLine(page);

                var pageNumbersToRender =
                    pagesToRender.Select(p => p.Number).ToArray();

                // Render only the beginning of each worksheet
                viewer.View(viewOptions, pageNumbersToRender);
            }
        }

        private static void SetLicense()
        {
            License license = new License();
            license.SetLicense("GroupDocs.Viewer.lic");
        }
    }
}

Let us know if you have any questions.

1 Like

This is exactly what I was looking for. Thank you very much.

Is there any documentation with this code snippet on?

1 Like

@Anf93

You’re welcome. The following documentation articles contain the information related to this issue

Let us know if you have any questions.