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:

  • Format - 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
  • DefaultFont - default font. The following font will be used if a spreadsheet font is missing
  • FontSubstitutes - substitute specific fonts from the source spreadsheet document
  • ShowGridLines - specifies that grid lines should be visible
  • ShowHiddenSheets - specifies that hidden sheet should be included in converted document
  • OnePagePerSheet - specifies that one sheet from the spreadsheet must be converted to single page
  • ConvertRange - specifies that specific range must be converted. Example: “D1:F8”
  • SkipEmptyRowsAndColumns - specifies that empty rows and columns must be ignored
  • Password -  password to unlock protected document
  • HideComments - 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:

Contracts.Func<LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
{
    HideComments = true,
    OnePagePerSheet = true
};
using (Converter converter = new Converter("sample.xlsx", getLoadOptions))
{
    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:

Contracts.Func<LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
{
    ShowGridLines = true,
    OnePagePerSheet = true
};
using (Converter converter = new Converter("sample.xlsx", getLoadOptions))
{
    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:

Contracts.Func<LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
{
    SkipEmptyRowsAndColumns = true,
    OnePagePerSheet = true
};
using (Converter converter = new Converter("sample.xlsx", getLoadOptions))
{
    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:

Contracts.Func<LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
{
    DefaultFont = "Helvetica",
    FontSubstitutes = new List<FontSubstitute>
    {
        FontSubstitute.Create("Tahoma", "Arial"),
        FontSubstitute.Create("Times New Roman", "Arial"),
    },
    OnePagePerSheet = true
};
using (Converter converter = new Converter("sample.xlsx", getLoadOptions))
{
    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

Contracts.Func<LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
{
    ConvertRange = "10:30",
    OnePagePerSheet = true
};
using (Converter converter = new Converter("sample.xlsx", getLoadOptions))
{
    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

Contracts.Func<LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
{
    ShowHiddenSheets = true,
    OnePagePerSheet = true
};
using (Converter converter = new Converter("sample.xlsx", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

More resources

Examples and Demos

Please find more use-cases and complete C# sources of our backend and frontend examples and try them for free!