【问题标题】:Preventing Excel from updating the screen in C#防止 Excel 在 C# 中更新屏幕
【发布时间】:2012-06-12 18:32:15
【问题描述】:

我正在用 VIsual C# for Excel 2010 编写一个插件。这个插件从我们的服务中检索一些数据并将结果写入某个电子表格的单元格。但是我不希望 Excel 显示用值填充单元格,因为这需要很多时间。所以我尝试了以下代码:

ExcelApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
ExcelApp.ScreenUpdating = false;
GetFolderTreeRecursive(FolderTree);
ExcelApp.ScreenUpdating = true;

GetFolderTreeRecursive 基本上处理 Web 服务调用并将响应值写入 Excel 单元格,如下所示:

Globals.TestCases.Cells[FolderTreeRowIndex, FolderTreeColumnIndex].Value2 = CurrentFolder.recordid;

不幸的是,Excel 仍然显示所有正在写入的单元格。我做错了什么?

【问题讨论】:

    标签: c# excel add-in


    【解决方案1】:

    我刚刚引用了错误的 Excel 应用程序对象。使用以下语句返回当前的 Excel 应用程序,而不是我意外实现的新应用程序。

    ExcelApp = Globals.ThisWorkbook.ThisApplication;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 2010-09-23
      • 2023-03-16
      • 2020-01-04
      相关资源
      最近更新 更多