Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

GroupDocs.Viewer for Python allows you to render your spreadsheet files in HTML, PDF, PNG, and JPEG formats. You do not need to use Microsoft Excel or other spreadsheet programs to load and view Excel documents within your Python application (web or desktop).

To start with the GroupDocs.Viewer API, create a Viewer class instance. Pass a spreadsheet file you want to view to the class constructor. You can load the document from a file or stream. Call one of the Viewer.view method overloads to convert the document to HTML, PDF, or image format. These methods allow you to render the entire document or specific pages.

View Excel files online View demos and examples on GitHub

Supported spreadsheet file formats

GroupDocs.Viewer supports the following spreadsheet file formats:

Render spreadsheets as HTML

Create an HtmlViewOptions class instance and pass it to the Viewer.view method to convert a spreadsheet file to HTML. The HtmlViewOptions class properties allow you to control the conversion process. For instance, you can embed all external resources in the generated HTML file, minify the output file, and optimize it for printing. Refer to the following documentation section for details: Rendering to HTML.

Create an HTML file with embedded resources

To save all elements of an HTML page (including text, graphics, and stylesheets) into a single file, call the HtmlViewOptions.for_embedded_resources method and specify the output file name.

Convert an Excel workbook to HTML

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_excel_to_html():
    # Load Excel spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to HTML.
        # {0} is replaced with the current page number in the file names.
        viewOptions = HtmlViewOptions.for_embedded_resources("render_excel_to_html/pdf_page_{0}.html")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_excel_to_html()

invoice.xlsx is the sample file used in this example. Click here to download it.

render_excel_to_html/pdf_page_1.html (77 KB)
render_excel_to_html/pdf_page_2.html (104 KB)
render_excel_to_html/pdf_page_3.html (74 KB)

Download full output

Convert an Apple Numbers spreadsheet to HTML

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_numbers_to_html():
    # Load Apple Numbers spreadsheet
    with Viewer("sample.numbers") as viewer:
        # Convert the spreadsheet to HTML.
        # {0} is replaced with the current page number in the file names.
        viewOptions = HtmlViewOptions.for_embedded_resources("render_numbers_to_html/pdf_page_{0}.html")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_numbers_to_html()

sample.numbers is the sample file used in this example. Click here to download it.

render_numbers_to_html/pdf_page_1.html (72 KB)
render_numbers_to_html/pdf_page_2.html (40 KB)

Download full output

Create an HTML file with external resources

If you want to store an HTML file and additional resource files (such as fonts, images, and stylesheets) separately, call the HtmlViewOptions.for_external_resources method and pass the following parameters:

  • The output file path format
  • The path format for the folder with external resources
  • The resource URL format

Convert an Excel workbook to HTML

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_excel_to_html_external():
    # Load Excel spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to HTML.
        # Specify the HTML file names and location of external resources.
        # {0} and {1} are replaced with the current page number and resource name, respectively.
        # The resource URL is relative to the HTML file.
        viewOptions = HtmlViewOptions.for_external_resources("render_excel_to_html_external/pdf_page_{0}.html", "render_excel_to_html_external/pdf_page_{0}/resource_{0}_{1}", "pdf_page_{0}/resource_{0}_{1}")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_excel_to_html_external()

invoice.xlsx is the sample file used in this example. Click here to download it.

render_excel_to_html_external/pdf_page_1.html (8 KB)
render_excel_to_html_external/pdf_page_1/resource_1_s.css (8 KB)
render_excel_to_html_external/pdf_page_2.html (32 KB)
render_excel_to_html_external/pdf_page_2/resource_2_s.css (8 KB)
render_excel_to_html_external/pdf_page_3.html (9 KB)
render_excel_to_html_external/pdf_page_3/resource_3_s.css (8 KB)

Download full output

Convert an Apple Numbers spreadsheet to HTML

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_numbers_to_html_external():
    # Load Apple Numbers spreadsheet
    with Viewer("sample.numbers") as viewer:
        # Convert the spreadsheet to HTML.
        # Specify the HTML file names and location of external resources.
        # {0} and {1} are replaced with the current page number and resource name, respectively.
        # The resource URL is relative to the HTML file.
        viewOptions = HtmlViewOptions.for_external_resources("render_numbers_to_html_external/pdf_page_{0}.html", "render_numbers_to_html_external/pdf_page_{0}/resource_{0}_{1}", "pdf_page_{0}/resource_{0}_{1}")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_numbers_to_html_external()

sample.numbers is the sample file used in this example. Click here to download it.

render_numbers_to_html_external/pdf_page_1.html (12 KB)
render_numbers_to_html_external/pdf_page_1/resource_1_s.css (2 KB)
render_numbers_to_html_external/pdf_page_2.html (4 KB)
render_numbers_to_html_external/pdf_page_2/resource_2_s.css (2 KB)

Download full output

External resources are placed in a separate folder.

Convert all Excel worksheets to one HTML file

To convert all worksheets to one HTML file, use the HtmlViewOptions.render_to_single_page method. This feature is supported in both cases - when converting to HTML with embedded and external resources.

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_excel_to_single_html():
    # Load Excel spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert all Excel worksheets to one HTML file.
        viewOptions = HtmlViewOptions.for_embedded_resources("render_excel_to_single_html/page.html")
        # Enable converting all worksheets to one file.
        viewOptions.render_to_single_page = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_excel_to_single_html()

invoice.xlsx is the sample file used in this example. Click here to download it.

HTML file (72 KB)

Download full output

Render spreadsheets as PDF

Create a PdfViewOptions class instance and pass it to the Viewer.view method to convert a spreadsheet file to PDF. The PdfViewOptions class properties allow you to control the conversion process. For instance, you can protect the output PDF file, reorder its pages, and specify the quality of document images. Refer to the following documentation section for details: Rendering to PDF.

Convert an Excel workbook to PDF

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions

def render_excel_to_pdf():
    # Load Excel spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("render_excel_to_pdf/spreadsheet.pdf")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_excel_to_pdf()

invoice.xlsx is the sample file used in this example. Click here to download it.

Binary file (PDF, 80 KB)

Download full output

Convert an Apple Numbers spreadsheet to PDF

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions

def render_numbers_to_pdf():
    # Load Apple Numbers spreadsheet
    with Viewer("sample.numbers") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("render_numbers_to_pdf/spreadsheet.pdf")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_numbers_to_pdf()

sample.numbers is the sample file used in this example. Click here to download it.

Binary file (PDF, 22 KB)

Download full output

Render spreadsheets as PNG

Create a PngViewOptions class instance and pass it to the Viewer.view method to convert a spreadsheet file to PNG. Use the PngViewOptions.height and PngViewOptions.width methods to specify the output image size in pixels.

Convert an Excel workbook to PNG

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions

def render_excel_to_png():
    # Load Excel spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PNG.
        # {0} is replaced with the current page number in the file names.
        viewOptions = PngViewOptions("render_excel_to_png/spreadsheet_page_0_{0}.png")
        # Set width and height.
        viewOptions.width = 800
        viewOptions.height = 900
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_excel_to_png()

invoice.xlsx is the sample file used in this example. Click here to download it.

render_excel_to_png/spreadsheet_page_0_1.png (64 KB)
render_excel_to_png/spreadsheet_page_0_2.png (360 KB)
render_excel_to_png/spreadsheet_page_0_3.png (91 KB)

Download full output

Convert an Apple Numbers spreadsheet to PNG

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions

def render_numbers_to_png():
    # Load Apple Numbers spreadsheet
    with Viewer("sample.numbers") as viewer:
        # Convert the spreadsheet to PNG.
        # {0} is replaced with the current page number in the file names.
        viewOptions = PngViewOptions("render_numbers_to_png/spreadsheet_page_0_{0}.png")
        # Set width and height.
        viewOptions.width = 800
        viewOptions.height = 900
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_numbers_to_png()

sample.numbers is the sample file used in this example. Click here to download it.

render_numbers_to_png/spreadsheet_page_0_1.png (149 KB)
render_numbers_to_png/spreadsheet_page_0_2.png (25 KB)

Download full output

Render spreadsheets as JPEG

Create a JpgViewOptions class instance and pass it to the Viewer.view method to convert a spreadsheet file to JPEG. Use the JpgViewOptions.height and JpgViewOptions.width methods to specify the output image size in pixels.

Convert an Excel workbook to JPEG

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import JpgViewOptions

def render_excel_to_jpg():
    # Load Excel spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to JPEG.
        # {0} is replaced with the current page number in the file names.
        viewOptions = JpgViewOptions("render_excel_to_jpg/excel_to_jpg_{0}.jpg")
        # Set width and height.
        viewOptions.width = 800
        viewOptions.height = 900
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_excel_to_jpg()

invoice.xlsx is the sample file used in this example. Click here to download it.

render_excel_to_jpg/excel_to_jpg_1.jpg (43 KB)
render_excel_to_jpg/excel_to_jpg_2.jpg (196 KB)
render_excel_to_jpg/excel_to_jpg_3.jpg (61 KB)

Download full output

Convert an Apple Numbers spreadsheet to JPEG

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import JpgViewOptions

def render_numbers_to_jpg():
    # Load Apple Numbers spreadsheet
    with Viewer("sample.numbers") as viewer:
        # Convert the spreadsheet to JPEG.
        # {0} is replaced with the current page number in the file names.
        viewOptions = JpgViewOptions("render_numbers_to_jpg/numbers_to_jpg_{0}.jpg")
        # Set width and height.
        viewOptions.width = 800
        viewOptions.height = 900
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_numbers_to_jpg()

sample.numbers is the sample file used in this example. Click here to download it.

render_numbers_to_jpg/numbers_to_jpg_1.jpg (127 KB)
render_numbers_to_jpg/numbers_to_jpg_2.jpg (27 KB)

Download full output

Detect a CSV/TSV separator

If you load a CSV/TSV file to convert it to another format, use the SpreadsheetOptions.detect_separator method for a target view to automatically detect a delimiter used to separate values in the source file.

GroupDocs.Viewer can detect the following separators:

  • A comma (the default separator)
  • A semicolon
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_csv_with_separator_detection():
    # Load CSV file
    with Viewer("sample.csv") as viewer:
        # Convert the spreadsheet to HTML.
        # {0} is replaced with the current page number in the file names.
        viewOptions = HtmlViewOptions.for_embedded_resources("render_csv_with_separator_detection/csv_with_separator_detection_{0}.html")
        # Detect a CSV/TSV separator.
        viewOptions.spreadsheet_options.detect_separator = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_csv_with_separator_detection()

sample.csv is the sample file used in this example. Click here to download it.

HTML file (52 KB)

Download full output

Get worksheet names

GroupDocs.Viewer allows you to obtain information about the source spreadsheet file. For example, you can retrieve worksheet names, as described below:

  1. Create a ViewInfoOptions instance for a specific view.
  2. Call the Viewer.get_view_info method and pass the ViewInfoOptions instance to this method as a parameter.
  3. Use the pages method of the returned ViewInfo object to access to the list of worksheets and retrieve the worksheet names.
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import ViewInfoOptions, SpreadsheetOptions

def get_worksheet_names():
    # Load Excel spreadsheet
    with Viewer("sample.xlsx") as viewer:
        view_info_options = ViewInfoOptions.for_html_view()
        # Call this method to create a single page for each worksheet.
        view_info_options.spreadsheet_options = SpreadsheetOptions.for_one_page_per_sheet()
        view_info = viewer.get_view_info(view_info_options)
        # Print the worksheet names in the console window.
        print("Worksheets:")
        for page in view_info.pages:
            print(f" - Worksheet {page.number} name '{page.name}'")

if __name__ == "__main__":
    get_worksheet_names()

sample.xlsx is the sample file used in this example. Click here to download it.

Worksheets:
 - Worksheet 1 name 'Summary'
 - Worksheet 2 name 'Orders'
 - Worksheet 3 name 'Customers'

Download full output

See also