A couple of days back I have got a call and asked how to convert Excel files to PDF using Spire.XLS a .NET component. Hereunder, I am just going to explain the same suing simple code snippet [here we are creating a simple xls file first]:
Create a file:
- public void CreateSampleExcel()
- {
- workSheet = workBook.Worksheets[0];
- workSheet.Range["A1"].Text = "This is a sample Excel dcouemnt and created by Spire.XLS for .NET";
- workBook.SaveToFile(_xlsFilePath + _xlsFileName);
- }
In above first we defined a path and initialize the object:
- private string _xlsFilePath = HttpContext.Current.Server.MapPath("~/Sample/XLSFiles/");
- public SpireExcel(string xlsFileName)
- {
- _xlsFileName = xlsFileName;
- workBook = new Workbook();
- }
There is no need for special settings or implementation just use inbuild functions to convert the file:
- workBook.SaveToFile(_xlsFilePath + "mySpirePDFFile.pdf");
And simply invoke this method:
- SpireExcel spireExcel = new SpireExcel();
- spireExcel.ConvertToPDF();
A complete source code file is attached. Alternatively you can find complete application from here: https://github.com/garora/EIceblueStuffs