Excel File Viewer – Display Excel Data using C#

You can programmatically display Excel data as HTML, PDF, or images in .NET applications, letting you share content without exposing the original file. This article shows how to build an Excel file viewer and display Excel data using C#.

The following topics are covered:

  • [C# Excel File Viewer API — Free Download][2]
  • [Display Excel Data in HTML using C#][3]
  • [Render Excel Data in PDF using C#][4]
  • [View Excel File as JPG Image using C#][5]
  • [Adjust Text Overflow in Cells using C#][6]
  • [Render Hidden Rows and Columns of Excel][7]
  • [Skip Empty Rows and Columns in Excel][8]
  • [Split Excel Worksheet by Rows and Columns][9]

C# Excel File Viewer API — Free Download

We use GroupDocs.Viewer for .NET to render XLS or XLSX files. It supports many spreadsheet formats. Download the DLL or install via NuGet.

PM> Install-Package GroupDocs.Viewer

Display Excel Data in HTML using C#

Render the Excel file to HTML with these steps:

  1. Load an Excel file using the [Viewer][16] class.
  2. Create an [HtmlViewOptions][17] instance for [EmbeddedResources][18].
  3. Set the output file path.
  4. Optionally enable [RenderToSinglePage][19].
  5. Call the [View()][20] method with the HtmlViewOptions.

The code sample shows how to render an Excel file in HTML using C#.

Display Excel Data in HTML using C#.

Display Excel Data in HTML using C#.

Render Excel Data in PDF using C#

Render the Excel file to PDF with these steps:

  1. Load an Excel file using the [Viewer][16] class.
  2. Create a [PdfViewOptions][24] instance.
  3. Set the output file path.
  4. Call the [View()][20] method with PdfViewOptions.

The code sample shows how to render an Excel file in PDF using C#.

Render Excel Data in PDF using C#.

Render Excel Data in PDF using C#.

View Excel File as JPG Image using C#

Render the Excel file to JPG images with these steps:

  1. Load an Excel file using the [Viewer][16] class.
  2. Create a [JpgViewOptions][23] instance.
  3. Set the output file path.
  4. Call the [View()][20] method with JpgViewOptions.

The code sample shows how to render an Excel file as JPG using C#.

View Excel File as JPG Image using C#.

View Excel File as JPG Image using C#.

You can also render to PNG images:

Adjust Text Overflow in Cells using C#

Control text overflow in cells with these options:

  • Overlay – overlay next cells even if they are not empty.
  • OverlayIfNextIsEmpty – overlay only when the next cell is empty.
  • AutoFitColumn – expand columns to fit the text.
  • HideText – hide overflow text.

Steps to set overflow mode:

  1. Load an Excel file using the [Viewer][16] class.
  2. Create a [PdfViewOptions][24] instance.
  3. Set the output file path.
  4. Set SpreadsheetOptions.TextOverflowMode to HideText.
  5. Optionally enable RenderHeadings and RenderGridLines.
  6. Call the [View()][20] method with PdfViewOptions.

The code sample shows how to adjust text overflow while rendering an Excel file using C#.

Adjust Text Overflow in Cells using C#.

Adjust Text Overflow in Cells using C#.

Render Hidden Rows and Columns of Excel

To include hidden rows and columns, set these properties to true:

viewOptions.SpreadsheetOptions.RenderHiddenColumns = true;
viewOptions.SpreadsheetOptions.RenderHiddenRows = true;

The code sample shows how to show hidden rows and columns of an Excel file in PDF using C#.

Render Hidden Rows and Columns of Excel.

Render Hidden Rows and Columns of Excel.

Skip Empty Rows and Columns in Excel using C#

To omit empty rows and columns, enable these options:

viewOptions.SpreadsheetOptions.SkipEmptyColumns = true;
viewOptions.SpreadsheetOptions.SkipEmptyRows = true;

The code sample shows how to skip empty rows and columns when rendering an Excel file using C#.

Skip Empty Rows and Columns in Excel using C#

Skip Empty Rows and Columns in Excel using C#.

Split Excel Worksheet by Rows and Columns

Render large worksheets by splitting them into pages. Follow these steps:

  1. Load an Excel file using the [Viewer][16] class.
  2. Create a [PdfViewOptions][24] instance.
  3. Set the output file path.
  4. Initialize SpreadsheetOptions with ForSplitSheetIntoPages(rowCount, columnCount).
  5. Call the [View()][20] method with PdfViewOptions.

The code sample shows how to split an Excel worksheet by rows and columns using C#.

Split Excel Worksheet by Rows and Columns

Split Excel Worksheet by Rows and Columns.

Get a Free License

Please try the API without evaluation limitations by requesting [a free temporary license][29].

Conclusion

In this article, we learned how to:

  • render Excel worksheets to HTML, PDF, PNG, and JPG using C#;
  • adjust text overflow and render grid lines;
  • display column and row headings;
  • skip empty rows/columns and show hidden rows/columns;
  • split worksheets by rows and columns.

Explore more about GroupDocs.Viewer for .NET in the [documentation][30]. For questions, visit the [forum][31].

See Also

  • [Insert or Delete Rows and Columns in Excel using C#][32]