private void ExportExcelToPDF()
{
string sourceFilePath = @"SourceFilePath";
string destinationFilePath = @"DestinationFilePath";
Microsoft.Office.Interop.Excel.Application myExcelApp;
Microsoft.Office.Interop.Excel.Workbooks myExcelWorkbooks = null;
Microsoft.Office.Interop.Excel.Workbook myExcelWorkbook = null;
try
{
object misValue = System.Reflection.Missing.Value;
myExcelApp = new Microsoft.Office.Interop.Excel.Application();
myExcelApp.Visible = true;
object varMissing = Type.Missing;
myExcelWorkbooks = myExcelApp.Workbooks;
//if file already exist then delete the file
if (System.IO.File.Exists(destinationFilePath))
{
System.IO.File.Delete(destinationFilePath);
}
myExcelWorkbook = myExcelWorkbooks.Open(sourceFilePath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
myExcelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
destinationFilePath, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard,
varMissing, false, varMissing, varMissing, false, varMissing);
myExcelWorkbooks.Close();
myExcelApp.Quit();
}
catch
{
}
finally
{
myExcelApp = null;
}
}
{
string sourceFilePath = @"SourceFilePath";
string destinationFilePath = @"DestinationFilePath";
Microsoft.Office.Interop.Excel.Application myExcelApp;
Microsoft.Office.Interop.Excel.Workbooks myExcelWorkbooks = null;
Microsoft.Office.Interop.Excel.Workbook myExcelWorkbook = null;
try
{
object misValue = System.Reflection.Missing.Value;
myExcelApp = new Microsoft.Office.Interop.Excel.Application();
myExcelApp.Visible = true;
object varMissing = Type.Missing;
myExcelWorkbooks = myExcelApp.Workbooks;
//if file already exist then delete the file
if (System.IO.File.Exists(destinationFilePath))
{
System.IO.File.Delete(destinationFilePath);
}
myExcelWorkbook = myExcelWorkbooks.Open(sourceFilePath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
myExcelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
destinationFilePath, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard,
varMissing, false, varMissing, varMissing, false, varMissing);
myExcelWorkbooks.Close();
myExcelApp.Quit();
}
catch
{
}
finally
{
myExcelApp = null;
}
}
No comments:
Post a Comment