I have an xlsx file that includes charts each in sheets. I want to save it as pdf file.
I made a sample using excel.interop:
Application excelApplication = new Application();
Workbook wkb = excelApplication.Workbooks.Open(oSlideMaster._FILE_PATH, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlNormalLoad);
var basePath = HttpRuntime.AppDomainAppPath;
wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, ExportExcelToPdfFullPathWithoutExt);
This code works on visual studio but it doesnt work on server without ms office 2007 or higher version installed.
Question is:
How can i convert (FREE) excel to pdf(include charts) without using excel.interop library. Because i dont want to install ms office on server side.
The point is that also: I tried some dll to convert excel to pdf, but i couldnt convert CHARTS only text i could convert successfully.
Thanks.
Download file.
Try with this following piece of code.
excelworkBook.SaveAs(saveAsLocation);
excelworkBook.Close();
excel.Quit();
bool flag=SaveAsPdf(saveAsLocation);
In this the saveAsLocation
is the full path of the execelworkBook
.After that it is converted into pdf using library Spire.Xls
.For that add the reference Spire.Xls
,which can be added to your project using Manage Nuget Packages
.
private bool SaveAsPdf(string saveAsLocation)
{
string saveas = (saveAsLocation.Split('.')[0]) + ".pdf";
try
{
Workbook workbook = new Workbook();
workbook.LoadFromFile(saveAsLocation);
//Save the document in PDF format
workbook.SaveToFile(saveas, Spire.Xls.FileFormat.PDF);
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With