Converting a document from XLSX to PDF format
Converting Excel files (XLSX) to PDF — whether for auditing, legal purposes, or archiving — ensures critical data is preserved in a tamper-proof form that maintains its original appearance.
How Nutrient helps you achieve this
Nutrient .NET SDK handles XLSX-to-PDF conversion. With the SDK, you don’t need to worry about:
- Parsing Excel file structures
- Managing spreadsheet layouts
- Handling cell formatting and styles
- Complex rendering logic
Instead, Nutrient provides an API that handles all the complexity behind the scenes, letting you focus on your business logic.
Complete implementation
Below is a complete working example that demonstrates XLSX-to-PDF conversion. This line sets up the C# application. The using directive brings in the Nutrient SDK namespace:
using Nutrient;This line opens the Excel file. The using declaration(opens in a new tab) ensures the document is automatically closed when it goes out of scope, preventing resource leaks:
try{ using Document document = Document.Open("input.xlsx");This block exports the document to PDF and saves it as output.pdf. The try-catch block handles potential errors using NutrientException:
document.ExportAsPdf("output.pdf"); Console.WriteLine("Successfully converted to output.pdf");}catch (NutrientException e){ Console.Error.WriteLine($"Error: {e.Message}"); Environment.Exit(1);}Conclusion
The conversion logic consists of two steps:
- Open the document.
- Export as PDF.
Nutrient handles Excel file parsing and PDF rendering so you don’t need to understand spreadsheet internals or manage complex layouts.