The following example shows the most common use case for converting Excel XLS document to PDF. The source XLS file is loaded from a current folder. The converted file is saved to the same folder.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Create a converter for the XLS filevarconverter=newXlsToPdfConverter("cost-analysis.xls");// Convert XLS to PDFconverter.Convert("cost-analysis.pdf");
ImportsSystemImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Create a converter from file path
DimconverterAsNewXlsToPdfConverter("cost-analysis.xls")' Convert XLS to PDF
converter.Convert("cost-analysis.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Create a converter from file path
letconverter=newXlsToPdfConverter("cost-analysis.xls")// Convert XLS to PDF
converter.Convert("cost-analysis.pdf")0
This section covers only the main scenarios. You can also refer to the API references for the SpreadsheetLoadOptions for a complete list of options that you can specify.
Convert Protected XLS to PDF
The following example shows how to convert protected XLS file and save it to unprotected PDF file.
In case you do not specify password for protected document PasswordRequiredException is going to be thrown.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Provide password through load optionsvarconverter=newXlsToPdfConverter("protected.xls",options=>{options.Password="12345";});// Convert XLS to PDFconverter.Convert("unprotected.pdf");
ImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Provide password through load options
DimconverterAsNewXlsToPdfConverter("protected.xls",Sub(options)options.Password="12345"EndSub)' Convert XLS to PDF
converter.Convert("unprotected.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Provide password through load options
letconverter=newXlsToPdfConverter("protected.xls",funoptions->options.Password<-"12345")// Convert XLS to PDF
converter.Convert("unprotected.pdf")0
The following example shows how to convert only specific sheets from an XLS file to PDF using the SheetIndexes property.
usingSystem;usingSystem.Collections.Generic;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Convert only specific sheets through load optionsvarconverter=newXlsToPdfConverter("invoice-tracker.xls",options=>{options.SheetIndexes=newList<int>{0,2};// Convert first and third sheets});// Convert XLS to PDFconverter.Convert("specific-sheets.pdf");
ImportsSystemImportsSystem.Collections.GenericImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Convert only specific sheets through load options
DimconverterAsNewXlsToPdfConverter("invoice-tracker.xls",Sub(options)options.SheetIndexes=NewList(OfInteger)From{0,2}' Convert first and third sheets
EndSub)' Convert XLS to PDF
converter.Convert("specific-sheets.pdf")EndSubEndModule
openSystemopenSystem.Collections.GenericopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Convert only specific sheets through load options
letconverter=newXlsToPdfConverter("invoice-tracker.xls",funoptions->options.SheetIndexes<-List<int>([0;2])// Convert first and third sheets
)// Convert XLS to PDF
converter.Convert("specific-sheets.pdf")0
By default hidden sheets are not added to the converted PDF document.
The following example shows how to include hidden sheets when converting XLS to PDF using the ShowHiddenSheets property.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Show hidden sheets through load optionsvarconverter=newXlsToPdfConverter("hidden-sheets.xls",options=>{options.ShowHiddenSheets=true;});// Convert XLS to PDFconverter.Convert("with-hidden-sheets.pdf");
ImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Show hidden sheets through load options
DimconverterAsNewXlsToPdfConverter("hidden-sheets.xls",Sub(options)options.ShowHiddenSheets=TrueEndSub)' Convert XLS to PDF
converter.Convert("with-hidden-sheets.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Show hidden sheets through load options
letconverter=newXlsToPdfConverter("hidden-sheets.xls",funoptions->options.ShowHiddenSheets<-true)// Convert XLS to PDF
converter.Convert("with-hidden-sheets.pdf")0
The examples in this section shows how you can adjust the output using PdfConvertOptions.
Convert XLS to PDF with Specific PDF Format
You can specify the PDF format for the output file using the PdfFormat property in PdfOptions class. This allows you to create PDF files that conform to specific standards like PDF/A for archiving or PDF/X for print production.
The following example shows how to convert an XLS file to PDF/A-1b format, which is commonly used for long-term archiving:
usingSystem;usingGroupDocs.Conversion.LowCode;usingGroupDocs.Conversion.Options.Convert;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Create the convertervarconverter=newXlsToPdfConverter("cost-analysis.xls");// Convert to PDF/A-1b format for archivingconverter.Convert("converted.pdf",convertOptions=>{convertOptions.PdfOptions.PdfFormat=PdfFormats.PdfA_1B;});
ImportsGroupDocs.Conversion.LowCodeImportsGroupDocs.Conversion.Options.ConvertModuleProgramSubMain()' Load license keys
DimpublicKeyAsString=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKeyAsString=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Create the converter
DimconverterAsNewXlsToPdfConverter("cost-analysis.xls")' Convert to PDF/A-1b format for archiving
converter.Convert("converted.pdf",Sub(convertOptions)convertOptions.PdfOptions.PdfFormat=PdfFormats.PdfA_1BEndSub)EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCodeopenGroupDocs.Conversion.Options.Convert[<EntryPoint>]letmainargv=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Create the converter
letconverter=newXlsToPdfConverter("cost-analysis.xls")// Convert to PDF/A-1b format for archiving
converter.Convert("converted.pdf",funconvertOptions->convertOptions.PdfOptions.PdfFormat<-PdfFormats.PdfA_1B)0//returnexitcode