Load Spreadsheet document with options
Leave feedback
On this page
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:
Option | Description |
---|---|
Format | The 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 |
AllColumnsInOnePagePerSheet | If 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. |
AutoFitRows | If enabled, automatically adjusts the content of all rows while converting. |
CheckExcelRestriction | Whether 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. |
DefaultFont | Specify the default font to use if a spreadsheet font is missing. |
FontSubstitutes | Substitute 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. |
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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.