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 setSpreadsheetOptions method for one of the following classes (depending on the output file format):
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).
Use the SpreadsheetOptions.setRenderHeadings method 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:
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.PdfViewOptions;// ...
try(Viewerviewer=newViewer("invoice.xlsx")){// Convert the spreadsheet to PDF.
PdfViewOptionsviewOptions=newPdfViewOptions("output.pdf");// Render row and column headings.
viewOptions.getSpreadsheetOptions().setRenderHeadings(true);viewer.view(viewOptions);}
The following code example demonstrates how to convert an Excel workbook to PDF and display gridlines in the output PDF file:
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.PdfViewOptions;// ...
try(Viewerviewer=newViewer("invoice.xlsx")){// Convert the spreadsheet to PDF.
PdfViewOptionsviewOptions=newPdfViewOptions("output.pdf");// Render gridlines.
viewOptions.getSpreadsheetOptions().setRenderGridLines(true);viewer.view(viewOptions);}
The following image demonstrates the result:
Control cell text overflow
The SpreadsheetOptions.setTextOverflowMode method 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.
You can set the TextOverflowMode property to one of the following values:
TextOverflowMode.OVERLAY_IF_NEXT_IS_EMPTY (default) — Allows text to overflow into adjacent cells if these cells have no data. If adjacent cells are not empty, the overflowing text is truncated.
TextOverflowMode.OVERLAY — Text always overflows into adjacent cells even if these cells contain data.
The following example demonstrates how to set this option in code:
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.PdfViewOptions;// ...
try(Viewerviewer=newViewer("invoice.xlsx")){// Convert the spreadsheet to PDF.
PdfViewOptionsviewOptions=newPdfViewOptions("output.pdf");// Specify the AutoFitColumn mode.
viewOptions.getSpreadsheetOptions().setTextOverflowMode(TextOverflowMode.AUTO_FIT_COLUMN);viewer.view(viewOptions);}
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.
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.PdfViewOptions;// ...
try(Viewerviewer=newViewer("invoice.xlsx")){// Convert the spreadsheet to PDF.
PdfViewOptionsviewOptions=newPdfViewOptions("output.pdf");// Enable rendering hidden rows and columns.
viewOptions.getSpreadsheetOptions().setRenderHiddenRows(true);viewOptions.getSpreadsheetOptions().setRenderHiddenColumns(true);viewer.view(viewOptions);}
The image below demonstrates the result. Hidden rows and columns appear in the generated PDF file.
Render hidden worksheets
If your spreadsheet file contains hidden worksheets, use the ViewOptions.setRenderHiddenPages method 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:
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.PdfViewOptions;// ...
try(Viewerviewer=newViewer("invoice.xlsx")){// Convert the spreadsheet to PDF.
PdfViewOptionsviewOptions=newPdfViewOptions("output.pdf");// Enable rendering hidden pages.
viewOptions.setRenderHiddenPages(true);viewer.view(viewOptions);}
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.PdfViewOptions;// ...
try(Viewerviewer=newViewer("invoice.xlsx")){// Convert the spreadsheet to PDF.
PdfViewOptionsviewOptions=newPdfViewOptions("output.pdf");// Enable skipping blank rows and columns.
viewOptions.getSpreadsheetOptions().setSkipEmptyRows(true);viewOptions.getSpreadsheetOptions().setSkipEmptyColumns(true);viewer.view(viewOptions);}
The following image demonstrates the result:
Render cell comments
Use the ViewOptions.setRenderComments method to display cell comments in the output file when you render your spreadsheet in HTML, PDF, PNG, or JPEG format.
importcom.groupdocs.viewer.Viewer;importcom.groupdocs.viewer.options.PdfViewOptions;// ...
try(Viewerviewer=newViewer("invoice.xlsx")){// Convert the spreadsheet to PDF.
PdfViewOptionsviewOptions=newPdfViewOptions("output.pdf");// Enable rendering comments.
viewOptions.setRenderComments(true);viewer.view(viewOptions);}
The following image demonstrates the result:
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.