返回首页

您好,

我在我的项目中使用Excel应用程序。我将保存在一个文件夹中的Excel模板,文件的扩展名是。XLSM(宏)。当我按一下按钮,将填补数据库提供的资料中的和我相同的扩展名保存同一个Excel在不同的文件夹中的所有工作在Microsoft Office 2007的罚款,但它不是在2003年的格式,它抛出一个错误的工作。任何一个可以帮助我解决这个问题。这里是代码:


 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;

 

        }

感谢Advancelt; LT ;/ xmlgt; :7946563 |会员

回答

评论会员: 时间:2
X