Load Spreadsheet document with options

GroupDocs.Conversion provides the SpreadsheetLoadOptions class which controls how the source spreadsheet will be processed. Below are some of the load options that you can use while converting spreadsheets:

OptionDescription
FormatThe document type is auto-detected while loading. However, you can explicitly specify the type of the source spreadsheet document. Available options are: Csv, Fods, Ods, Ots, Tsv, Xlam, Xls, Xlsb, Xlsm, Xlsx, Xlt, Xltm, Xltx
AllColumnsInOnePagePerSheetIf true, all column content from a single sheet will be converted into a single page. The width of paper size of page setup will be ignored, while keeping the rest of page settings. 
AutoFitRowsIf enabled, automatically adjusts the content of all rows while converting. 
CheckExcelRestrictionWhether to check restrictions of Excel file when modifying cell objects. 
ConvertRange Defines a specific range of cells to be converted. For example: “D1:F8”
CultureInfo Specifies system culture info at the time file is loaded.
DefaultFontSpecify the default font to use if a spreadsheet font is missing.
FontSubstitutesSubstitute specific fonts from the source spreadsheet.
HideComments Specify if the comments from the source spreadsheet should be hidden during conversion.
OnePagePerSheet If specified, each spreadsheet will be converted into a single page.
OptimizePdfSize If enabled, optimizes the resulting PDF for smaller file size, rather than for better print quality.
Password  Defines a password to unlock a protected document.
SheetIndexes Defines the indexes of the particular sheets to be converted.
Sheets Defines the names of the particular sheets to be converted.
ShowGridLines Specify if the grid lines should be visible.
ShowHiddenSheets Specify if the hidden sheets should be included in the converted document.
SkipEmptyRowsAndColumns Specify if empty rows and columns should be ignored.

Hide comments

The following code snippet shows how to convert a spreadsheet 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 snippet shows how to convert a spreadsheet 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 snippet shows how to convert a spreadsheet 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 snippet shows how to convert a spreadsheet 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 particular sheets

You can specify the sheets to be converted either by names or by indexes.

The following code snippet shows how to convert a spreadsheet and specify the desired sheets by their names:

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

The following code snippet shows how to convert a spreadsheet and specify the desired sheets by their zero-based indexes:

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

Specify range

The following code snippet shows how to convert a spreadsheet and specify the 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 snippet shows how to convert a spreadsheet 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);
}

Automatically fit rows

To fit the row content of all rows while converting from a spreadsheet, set the AutoFitRows property to true:

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