export excel to pdf formate in c#
-
Hi, I have an asp.net web application. I have an excel sheet and I have to export that excel sheet to a pdf file. I have done it, but still facing some problems. 1. Whenever I do export, its open excel file. I do not want to open the excel file. 2. I have to convert the pdf file to landscape. Here is the code
private void ExportExcelToPDF()
{string sourceFilePath = Server.MapPath("~/aaa.xlsx"); string destinationFilePath = Server.MapPath("~/aaa.pdf"); 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.ApplicationClass(); 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; } }
Pankaj
-
Hi, I have an asp.net web application. I have an excel sheet and I have to export that excel sheet to a pdf file. I have done it, but still facing some problems. 1. Whenever I do export, its open excel file. I do not want to open the excel file. 2. I have to convert the pdf file to landscape. Here is the code
private void ExportExcelToPDF()
{string sourceFilePath = Server.MapPath("~/aaa.xlsx"); string destinationFilePath = Server.MapPath("~/aaa.pdf"); 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.ApplicationClass(); 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; } }
Pankaj
Pankaj Saha wrote:
1. Whenever I do export, its open excel file. I do not want to open the excel file.
I got the solution for this. Actually I did not see that little important thing. :omg:
myExcelApp.Visible = false;
now excel file is not opening. Now need the solution for the second problem. :confused:
Pankaj