Related blog post: How to Convert Excel Spreadsheets using C#
Last active
November 19, 2021 13:20
-
-
Save GroupDocsGists/9f28fd2d21f1593ba5d55cc9bb7faa36 to your computer and use it in GitHub Desktop.
Convert Excel Spreadsheet to PDF using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Convert the specified Cell Range of specified Excel sheets to PDF format using C# | |
*/ | |
// Prepare Load options and Range for the source XLSX file | |
Func<LoadOptions> loadOptions = () => new SpreadsheetLoadOptions | |
{ | |
ConvertRange = "A1:C20" | |
}; | |
using (var converter = new Converter(@"path/spreadsheet.xlsx", loadOptions)) | |
{ | |
var convertOptions = new PdfConvertOptions() | |
{ | |
PageNumber = 2, | |
PagesCount = 3 | |
// Pages = new System.Collections.Generic.List<int> { 2,3,4} | |
}; | |
// Save as PDF after conversion | |
converter.Convert(@"path/cell-range-converted.pdf", convertOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Convert all the Excel sheets to PDF format using C# | |
*/ | |
// Prepare Load options and Range for the source XLSX file | |
Func<LoadOptions> loadOptions = () => new SpreadsheetLoadOptions | |
{ | |
OnePagePerSheet = true | |
}; | |
using (var converter = new GroupDocs.Conversion.Converter(@"path/spreadsheet.xlsx", loadOptions)) | |
{ | |
// Convert and save the spreadsheet in PDF format | |
converter.Convert(@"path/all-sheets-converted.pdf", new PdfConvertOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Convert sequence of Excel sheets to PDF format using C# | |
*/ | |
using (var converter = new GroupDocs.Conversion.Converter(@"path/spreadsheet.xlsx")) | |
{ | |
// Set the starting sheet number and consecutive sheet count | |
var convertOptions = new PdfConvertOptions() | |
{ | |
PageNumber = 2, | |
PagesCount = 3 | |
}; | |
// Convert and save the spreadsheet in PDF format | |
converter.Convert(@"path/sequential-sheets-converted.pdf", convertOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Convert the specified list of Excel sheets to PDF format using C# | |
*/ | |
using (var converter = new GroupDocs.Conversion.Converter(@"path/spreadsheet.xlsx")) | |
{ | |
// Set the list to sheet numbers on convert | |
var convertOptions = new PdfConvertOptions() | |
{ | |
Pages = new System.Collections.Generic.List<int> { 1,3,5} | |
}; | |
// Convert and save the spreadsheet into PDF format | |
converter.Convert(@"path/selected-sheets-conversion.pdf", convertOptions); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment