1

我有一个自定义的 Excel 用户定义函数 ( ),它可以将数据从数据库获取到 Excel 工作表。当我从 ac# 代码执行此函数 ( =getData(A1,B1)) 以获取 excel 文件上的数据时,它将被放在一个单元格上而不被执行,直到我手动打开文件。这是我的代码的一部分:

var rng = workSheet.Range["A2"];  //where I will put the result table
            try{

            rng.Formula = @"=getData(A1,B1)"; //A1 =Cell from where the function   will get first argument
            String formula = rng.Formula.ToString(); 
            rng.FormulaHidden = false;
            workSheet.Unprotect();
            workBook.SaveAs(filePath, AccessMode: IExcel.XlSaveAsAccessMode.xlExclusive);
            formula = rng.Formula;  
            bool hidden = rng.FormulaHidden;

        }
catch.....
//close opened instances of the Excel file

是否有任何解决方案可以自动生成结果并在生成结果时阻止(从数据库获取数据需要一段时间)

4

0 回答 0