简体   繁体   English

excel文件值未更新

[英]excel file values are not updating

In my application i have an excel sheet with button. 在我的应用程序中,我有一个带有按钮的Excel工作表。 Using C# code i'm calling the button of excel file and the excel file click event also working very fine. 使用C#代码,我调用excel文件的按钮,并且excel文件单击事件也很好地工作。 I placed msg box in macros in that way i verified the click event of the excel sheet button working fine.But after running the macro the values are not updating in excel sheet. 我以这种方式将msg框放在宏中,我验证了excel工作表按钮的click事件是否正常。但是运行宏后,值不会在excel工作表中更新。 Please refer my code below , 请参考下面的代码

using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook;
xlWorkBook = xlApp.Workbooks.Open("D:test.xlsm", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
Excel.Worksheet xlWorkSheet;
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlApp.Run("Module1.solver", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkBook.Close(false, Type.Missing, Type.Missing);
 xlApp.Quit();
releaseObject(xlApp);
releaseObject(xlWorkBook);
private void releaseObject(object obj)
    {
        try
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
            obj = null;
        }
        catch (Exception ex)
        {
            throw (ex);
            obj = null;
        }
        finally
        {
            GC.Collect();
        }
    }  

Am I missing some function to update excel file ? 我缺少一些更新Excel文件的功能吗? And the macros I'm using are 我正在使用的宏是

SolverOk SetCell:="$A$6", MaxMinVal:=2, ValueOf:=0, ByChange:="$A$4:$A$6", _
    apple:=1, applecurry:="GRG Nonlinear"
MsgBox "$3"
SolverOk SetCell:="$A$6", MaxMinVal:=2, ValueOf:=0, ByChange:="$A$4:$A$6", _
    apple:=1, applecurry:="GRG Nonlinear"
MsgBox "$4"
SolverSolve

When you start Excel via automation, any add-ins or items in the xlstart folder are not loaded. 通过自动化启动Excel时,不会加载xlstart文件夹中的任何加载项或项目。

If your code relies on add-ins being loaded, then you will need to load them via your code. 如果您的代码依赖于加载的加载项,那么您将需要通过代码加载它们。

See: https://support.microsoft.com/en-us/kb/213489 请参阅: https//support.microsoft.com/en-us/kb/213489

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM