19.2-Creating Currency Converter
19.2-Creating Currency Converter
Program
using System;
using System.IO;
namespace DocumentConverter
class Program
ConvertExcelToPDF("input.xlsx", "output.pdf");
ConvertWordToPDF("input.docx", "output.pdf");
package.SaveAs(stream);
doc.Save(outputPath, SaveFormat.Pdf);
Exercise
Write a C# program that that converts Excel (.xlsx) and Word (.docx) documents to PDF format. You
will use two popular libraries: EPPlus for handling Excel documents and Aspose.Words for handling
Word documents.
Implement a method named ConvertExcelToPDF that takes two parameters: inputPath (string) and
outputPath (string).
Use EPPlus library to load the Excel file specified by inputPath.
Save the Excel document as a PDF file at the location specified by outputPath.
Implement a method named ConvertWordToPDF that takes two parameters: inputPath (string) and
outputPath (string).
Save the Word document as a PDF file at the location specified by outputPath.
In the Main method, demonstrate the usage of both conversion methods by converting sample Excel
and Word documents to PDF. You can provide sample input files such as "input.xlsx" and
"input.docx".
Hint
Ensure to include error handling mechanisms, such as try-catch blocks, to handle potential
Check the compatibility and version requirements of EPPlus and Aspose.Words libraries to ensure
they are compatible with your .NET environment and the targeted document formats.
Consider providing user-friendly feedback or progress updates during the conversion process, such
Explanation
This program is a document converter application that converts both Excel (.xlsx) and Word (.docx)
documents to PDF format. It utilizes two popular libraries, EPPlus for Excel handling and
Aspose.Words for Word document manipulation, both of which need to be installed via NuGet.
In the Main method, two conversion tasks are initiated sequentially. First, the ConvertExcelToPDF
method is called with the input Excel file path ("input.xlsx") and the desired output PDF file path
("output.pdf"). Similarly, the ConvertWordToPDF method is called with the input Word file path
("input.docx") and the same output PDF file path ("output.pdf").
The ConvertExcelToPDF method takes an input file path and an output file path as parameters. It
loads the Excel file using EPPlus, then creates a FileStream to write the converted PDF file. After
saving the Excel package as a PDF document, it displays a success message indicating the
Similarly, the ConvertWordToPDF method takes an input file path and an output file path as
parameters. It loads the Word document using Aspose.Words, then saves it as a PDF document at
the specified output path. Like the Excel conversion method, it also displays a success message
upon completion.