using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication
application = excelEngine.Excel;
application.DefaultVersion
= ExcelVersion.Xlsx;
FileStream excelStream
= new FileStream("Book1.xlsx",
FileMode.Open, FileAccess.Read);
IWorkbook workbook =
application.Workbooks.Open(excelStream);
IStyle style =
workbook.Styles.Add("Style");
style.NumberFormat = "DD/MM/YYYY";
workbook.Worksheets[0].SetDefaultColumnStyle(1,
style);
//Initialize XlsIO renderer.
XlsIORenderer renderer
= new XlsIORenderer();
//Convert Excel document into PDF document
PdfDocument
pdfDocument = renderer.ConvertToPDF(workbook);
MemoryStream stream = new MemoryStream();
pdfDocument.Save(stream);
//Set the position as '0'.
stream.Position = 0;
//Download the PDF document in the browser.
FileStreamResult
fileStreamResult = new
FileStreamResult(stream, "application/pdf");
fileStreamResult.FileDownloadName
= "Sample.pdf";
return fileStreamResult;
}
|