Load Spreadsheet document with options

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

  • setFormat - the document type is auto detected during loading, however you can 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 - default font. The following font will be used if a spreadsheet font is missing.
  • setFontSubstitutes - 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 converted document
  • setOnePagePerSheet - specifies that one sheet from the spreadsheet must be converted to single page
  • setConvertRange - specifies that specific range must be converted. Example: “D1:F8”
  • setSkipEmptyRowsAndColumns - specifies that empty rows and columns must be ignored.
  • setPassword -  password to unlock protected document
  • setHideComments - specifies that comments from source spreadsheet must be hidden during conversion

Hide comments

The following code sample shows how to convert Spreadsheet document and hide comments:

SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setHideComments(true);
loadOptions.setOnePagePerSheet(true);

Converter converter = new Converter("sample.xlsx", loadOptions);
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted.pdf", options);

Show grid lines

The following code sample shows how to convert Spreadsheet document and show grid lines:

SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setShowGridLines(true);
loadOptions.setOnePagePerSheet(true);

Converter converter = new Converter("sample.xlsx", loadOptions);
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted.pdf", options);

Skip empty rows and columns

The following code sample shows how to convert Spreadsheet document and skip empty rows and columns:

SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setSkipEmptyRowsAndColumns(true);
loadOptions.setOnePagePerSheet(true);

Converter converter = new Converter("sample.xlsx", loadOptions);
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted.pdf", options);

Specify font substitution

The following code sample shows how to convert Spreadsheet document and specify font substitution for missing fonts:

SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
List<FontSubstitute> fontSubstitutes = new ArrayList<FontSubstitute>();
fontSubstitutes.add(FontSubstitute.create("Tahoma", "Arial"));
fontSubstitutes.add(FontSubstitute.create("Times New Roman", "Arial"));
loadOptions.setDefaultFont("Helvetica");
loadOptions.setOnePagePerSheet(true);
loadOptions.setFontSubstitutes(fontSubstitutes);

Converter converter = new Converter("sample.xlsx", loadOptions);
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted.pdf", options);

Specify range

The following code sample shows how to convert Spreadsheet document and specify exact range of rows and columns to be converted

SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setConvertRange("10:30");
loadOptions.setOnePagePerSheet(true);

Converter converter = new Converter("sample.xlsx", loadOptions);
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted.pdf", options);

Include hidden sheets

The following code sample shows how to convert Spreadsheet document including the hidden sheets

SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setShowHiddenSheets(true);
loadOptions.setOnePagePerSheet(true);

Converter converter = new Converter("sample.xlsx", loadOptions);
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted.pdf", options);