public static void ConvertExcel(string SourceFile, string DestinatioFile)
{
//SourceFile:- c:\ab.xls or .xlsx
//DestinatioFile :- d:\\ab.pdf
object missing = System.Reflection.Missing.Value;
msExcel.Application excel = new msExcel.Application();
try
{
excel.Visible = false;
excel.ScreenUpdating = false;
excel.DisplayAlerts = false;
msExcel.Workbook wbk = excel.Workbooks.Open(SourceFile, missing,
missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing,
missing, missing, missing);
wbk.Activate();
msExcel.XlFixedFormatType fileFormat = msExcel.XlFixedFormatType.xlTypePDF;
// Save document into PDF Format
wbk.ExportAsFixedFormat(fileFormat, DestinatioFile,
missing, missing, missing,
missing, missing, missing,
missing);
object saveChanges = msExcel.XlSaveAction.xlDoNotSaveChanges;
((msExcel._Workbook)wbk).Close(saveChanges, missing, missing);
wbk = null;
}
finally
{
((msExcel._Application)excel).Quit();
excel = null;
}
}
No comments:
Post a Comment