Specify spreadsheet rendering options

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 ships with the SpreadsheetOptions class that allows you to specify different spreadsheet rendering options (for example, you can display row and column headings in the output file, render grid lines, or adjust cell text overflow). To access these options, use the SpreadsheetOptions property for one of the following classes (depending on the output file format):

Render row and column headings

Rows and columns in a worksheet have unique names displayed on the worksheet’s left and top side. Rows are numbered (1, 2, 3, …, 1048576), and columns are lettered (A, B, C, …, XFD).

Row and column headings in a worksheet

Enable the SpreadsheetOptions.render_headings property to display row and column headings in the output file when you render your spreadsheet in HTML, PDF, PNG, or JPEG format.

The following example demonstrates how to convert an Excel workbook to PDF and display row and column headings in the output PDF file:

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

def render_headings():
    # Load spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("render_headings/headings.pdf")
        # Render row and column headings.
        viewOptions.spreadsheet_options.render_headings = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_headings()

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

Binary file (PDF, 85 KB)

Download full output

Render worksheet gridlines

Use the SpreadsheetOptions.render_grid_lines property to display gridlines (lines that separate worksheet rows and columns) in the output file.

The following code example demonstrates how to convert an Excel workbook to PDF and display gridlines in the output PDF file:

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

def render_grid_lines():
    # Load spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("render_grid_lines/grid_lines.pdf")
        # Render grid lines.
        viewOptions.spreadsheet_options.render_grid_lines = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_grid_lines()

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

Binary file (PDF, 81 KB)

Download full output

Control cell text overflow

The SpreadsheetOptions.text_overflow_mode option allows you to prevent text overflow in worksheet cells (see the image below) when you convert your spreadsheet file to HTML, PDF, or image format.

Text overflow in a cell

You can set the text_overflow_mode property to one of the following values:

The following example demonstrates how to set this option in code:

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

def set_text_overflow_mode():
    # Load spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("set_text_overflow_mode/text_overflow_mode.pdf")
        # Specify the AUTO_FIT_COLUMN mode.
        viewOptions.spreadsheet_options.text_overflow_mode = TextOverflowMode.AUTO_FIT_COLUMN 
        viewer.view(viewOptions)

if __name__ == "__main__":
    set_text_overflow_mode()

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

Binary file (PDF, 80 KB)

Download full output

Render hidden rows and columns

Use the ViewOptions.SpreadsheetOptions.render_hidden_rows and ViewOptions.SpreadsheetOptions.render_hidden_columns properties to display hidden rows and columns in the output file when you render your spreadsheet in HTML, PDF, PNG, or JPEG format.

The example below demonstrates how to set this option in code. The rows 20 and 21 and the column E are hidden in the source Excel workbook.

Hidden rows and columns in a worksheet

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

def render_hidden_rows_and_columns():
    # Load spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("render_hidden_rows_and_columns/hidden_rows_and_columns.pdf")
        # Enable rendering hidden rows and columns.
        viewOptions.spreadsheet_options.render_hidden_columns = True
        viewOptions.spreadsheet_options.render_hidden_rows = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_hidden_rows_and_columns()

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

Binary file (PDF, 81 KB)

Download full output

Hidden rows and columns appear in the generated PDF file.

Render hidden worksheets

If your spreadsheet file contains hidden worksheets, enable the ViewOptions.render_hidden_pages property to display data from hidden worksheets in the output HTML, PDF, or image files.

The following example demonstrates how to set this option in code:

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

def render_hidden_pages():
    # Load spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("render_hidden_pages/hidden_pages.pdf")
        # Enable rendering hidden pages.
        viewOptions.render_hidden_pages = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_hidden_pages()

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

Binary file (PDF, 83 KB)

Download full output

Skip empty rows and columns

GroupDocs.Viewer supports the SpreadsheetOptions.skip_empty_rows and SpreadsheetOptions.skip_empty_columns properties that allow you to skip blank rows and columns when you convert your spreadsheet file to HTML, PDF, or image format.

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

def skip_empty_rows_and_columns():
    # Load spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        # Convert the spreadsheet to PDF.
        viewOptions = PdfViewOptions("skip_empty_rows_and_columns/skip_empty_rows_and_columns.pdf")
        # Enable skipping blank rows and columns.
        viewOptions.spreadsheet_options.skip_empty_columns = True
        viewOptions.spreadsheet_options.skip_empty_rows = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    skip_empty_rows_and_columns()

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

Binary file (PDF, 80 KB)

Download full output

Render cell comments

Cell comments are rendered by default: the ViewOptions.render_comments property is True unless you change it. The example below sets it explicitly; set it to False to hide the comments when you render your spreadsheet in HTML, PDF, PNG, or JPEG format.

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

def render_comments():
    # Load spreadsheet
    with Viewer("with_comments.xlsx") as viewer:
        # Convert the spreadsheet to PNG.
        # {0} is replaced with the current page number in the file names.
        viewOptions = PngViewOptions("render_comments/comments_{0}.png")
        # Enable rendering comments.
        viewOptions.render_comments = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_comments()

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

render_comments/comments_1.png (17 KB)
render_comments/comments_2.png (65 KB)
render_comments/comments_3.png (21 KB)

Download full output

Set worksheet margins in the output pdf pages

Use the SpreadsheetOptions.left_margin, right_margin, top_margin and bottom_margin properties to set margins for worksheets in the output pdf. If margins are set to value less than 0 or not set then default value will be used.

The following code example demonstrates how to convert an Excel workbook to PDF and set optional margins for worksheets in the output PDF file:

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

def set_worksheet_margins():

    # Load spreadsheet
    with Viewer("invoice.xlsx") as viewer:
        viewOptions = PdfViewOptions("set_worksheet_margins/worksheet_margins.pdf")

        # Set margins for worksheets in the output pdf pages
        viewOptions.spreadsheet_options.left_margin = 0.0
        viewOptions.spreadsheet_options.right_margin = 0.5
        viewOptions.spreadsheet_options.top_margin = 1.0
        viewOptions.spreadsheet_options.bottom_margin = -10.0
        viewer.view(viewOptions)

if __name__ == "__main__":
    set_worksheet_margins()

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

Binary file (PDF, 81 KB)

Download full output