Load Spreadsheet document with options

GroupDocs.Conversion provides SpreadsheetLoadOptions to give you control over how the source spreadsheet document will be processed. The following options could be set:

  • setFormat allows you to specify explicitly the type of the source spreadsheet document. Available options are: Xls, Xlsx, Xlsm, Xlsb, Ods, Ots, Xltx, Xlt, Xltm, Tsv, Xlam, Csv.
  • setDefaultFont sets a default font. The following font will be used if a spreadsheet font is missing.
  • setFontSubstitutes sets substitute specific fonts from the source spreadsheet document.
  • setShowGridLines specifies that grid lines should be visible.
  • setShowHiddenSheets specifies that hidden sheet should be included in the converted document.
  • setOnePagePerSheet specifies that one sheet from the spreadsheet must be converted to a single page.
  • setConvertRange specifies that a specific range of cells must be converted. Example: “D1:F8”.
  • setSkipEmptyRowsAndColumns specifies that empty rows and columns must be ignored.
  • setPassword specifies a password to unlock the protected document.
  • setHideComments specifies that comments from the source spreadsheet must be hidden during conversion.

Hide comments

The following code snippet shows how to convert a spreadsheet and hide comments:

const loadOptions = new groupdocs.conversion.SpreadsheetLoadOptions();
loadOptions.setHideComments(true);
loadOptions.setOnePagePerSheet(true);

const outputPath = "ConvertSpreadsheetAndHideComments.pdf";

const converter = new groupdocs.conversion.Converter("sample.xlsx", loadOptions);
const convertOptions = new groupdocs.conversion.PdfConvertOptions();

console.log(`Spreadsheet document converted successfully to ${outputPath} (hide comments)`);
converter.convert(outputPath, convertOptions);

Show grid lines

The following code snippet shows how to convert a spreadsheet and show grid lines:

const loadOptions = new groupdocs.conversion.SpreadsheetLoadOptions();
loadOptions.setShowGridLines(true);
loadOptions.setOnePagePerSheet(true);

const outputPath = "ConvertSpreadsheetByShowingGridLines.pdf";

const converter = new groupdocs.conversion.Converter("sample.xlsx", loadOptions);
const convertOptions = new groupdocs.conversion.PdfConvertOptions();

console.log(`Spreadsheet document converted successfully to ${outputPath} (show grid lines)`);
converter.convert(outputPath, convertOptions);

Skip empty rows and columns

The following code snippet shows how to convert a spreadsheet and skip empty rows and columns:

const loadOptions = new groupdocs.conversion.SpreadsheetLoadOptions();
loadOptions.setSkipEmptyRowsAndColumns(true);
loadOptions.setOnePagePerSheet(true);

const outputPath = "ConvertSpreadsheetBySkippingEmptyRowsAndColumns.pdf";

const converter = new groupdocs.conversion.Converter("sample.xlsx", loadOptions);
const convertOptions = new groupdocs.conversion.PdfConvertOptions();

console.log(`Spreadsheet document converted successfully to ${outputPath} (skip empty rows & columns)`);
converter.convert(outputPath, convertOptions);

Specify font substitution

The following code snippet shows how to convert a spreadsheet and specify font substitution for missing fonts:

const java = require('java');

const outputPath = "ConvertSpreadsheetBySpecifyingFontsubstitution.pdf";

const fontSubstitutes = java.newInstanceSync("java.util.ArrayList");
fontSubstitutes.add(groupdocs.conversion.FontSubstitute.create("Tahoma", "Arial"));
fontSubstitutes.add(groupdocs.conversion.FontSubstitute.create("Times New Roman", "Arial"));

const loadOptions = new groupdocs.conversion.SpreadsheetLoadOptions();
loadOptions.setDefaultFont("Helvetica.ttf");
loadOptions.setOnePagePerSheet(true);
loadOptions.setFontSubstitutes(fontSubstitutes);

const converter = new groupdocs.conversion.Converter("sample.xlsx", loadOptions);
const convertOptions = new groupdocs.conversion.PdfConvertOptions();

console.log(`Spreadsheet document converted successfully to ${outputPath} (by specifying font subs)`);
converter.convert(outputPath, convertOptions);

Specify range

The following code snippet shows how to convert a spreadsheet and specify the exact range of rows and columns to be converted:

const loadOptions = new groupdocs.conversion.SpreadsheetLoadOptions();
loadOptions.setConvertRange('10:30');
loadOptions.setOnePagePerSheet(true);

const outputPath = "ConvertSpreadsheetBySpecifyingRange.pdf";

const converter = new groupdocs.conversion.Converter("sample.xlsx", loadOptions);
const convertOptions = new groupdocs.conversion.PdfConvertOptions();

console.log(`Spreadsheet document converted successfully to ${outputPath} (by specifying range)`);
converter.convert(outputPath, convertOptions);

Include hidden sheets

The following code snippet shows how to convert a spreadsheet including the hidden sheets:

const loadOptions = new groupdocs.conversion.SpreadsheetLoadOptions();
loadOptions.setShowHiddenSheets(true);
loadOptions.setOnePagePerSheet(true);

const outputPath = "ConvertSpreadsheetWithHiddenSheetsIncluded.pdf";

const converter = new groupdocs.conversion.Converter("sample.xlsx", loadOptions);
const convertOptions = new groupdocs.conversion.PdfConvertOptions();

console.log(`Spreadsheet document converted successfully to ${outputPath} (with hidden sheets included)`);
converter.convert(outputPath, convertOptions);