Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using the excel application in my project. I will save the excel template in one folder, the extension of the file is .xlsm(with macros). When I click the button the datas that are available in database will be filled and I am saving the same excel with the same extension in different folder its all working fine in microsoft office 2007, but its not working in 2003 format it throws an error. Can any one help me to solve this problem. Here is the code:


protected void btnExcelDownload_Click(object sender, EventArgs e)
   {
       try
       {

           excelApp = new Excel.ApplicationClass();  // Creates a new Excel Application
           excelApp.Visible = false;  // Makes Excel visible to the user.
           // The following code opens an existing workbook
           string workbookPath =Server.MapPath("~/Format/RiTE_Template.xlsm");
           //string workbookPath = Server.MapPath(Request.ApplicationPath) + @"\Format\RiTE_Template.xlsm";  // Add your own path here
           excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
               false, 0, true, false, false);
           // The following gets the Worksheets collection
           excelSheets = excelWorkbook.Worksheets;
          if ()
           {
              //here I am filling the excel worksheets
           }

               string filename = "Rite File" + "_" + SessionVarriables.BidIdSession + "_" + SessionVarriables.RevisionNumberSession;
               excelWorkbook.SaveAs(Server.MapPath("~/RiteFile/") + filename + ".xlsm");
               string path = Server.MapPath("~/RiteFile/") + filename + ".xlsm";
               excelApp.DisplayAlerts = false;
               excelApp.UserControl = false;
               excelWorkbook.Close();
               excelApp.Workbooks.Close();
               excelApp.Quit();
               System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
               System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
               excelWorkbook = null;
               excelApp = null;
               System.Diagnostics.Process.Start(path);
           }
       }
       catch (Exception ex)
       {

           excelApp.DisplayAlerts = false;
           excelApp.UserControl = false;
           excelApp.Workbooks.Close();
           excelApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
           excelApp = null;

       }

Thanks in Advance<</xml>
Posted
Comments
RaviRanjanKr 10-Oct-11 7:09am    
Please mention exception in your question. :)

 
Share this answer
 
v2
.xlsm are Excel 2007 Macro-Enabled Spreadsheet files and not supprted to excel 2003
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900