简体   繁体   English

防止Excel更新C#中的屏幕

[英]Preventing Excel from updating the screen in C#

I am writing an add-in in VIsual C# for Excel 2010. This add-in retrieves some data from a we service and writes the results into cells of a certain spreadsheet. 我正在用Excel 2010的VIsual C#编写加载项。此加载项从we服务检索一些数据,并将结果写入特定电子表格的单元格中。 However I don't want Excel to display filling the cells with values as this takes a lot of time. 但是我不希望Excel显示用值填充单元格,因为这需要很多时间。 So I tried the following piece of code: 所以我尝试了以下代码:

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

GetFolderTreeRecursive basically handles the web service call and writes response values to Excel cells like this: GetFolderTreeRecursive基本上处理Web服务调用并将响应值写入Excel单元格,如下所示:

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

Unfortunately Excel still displays all of the cells being written. 不幸的是,Excel仍然显示所有正在写入的单元格。 What am I doing wrong? 我究竟做错了什么?

I just referenced the wrong Excel application object. 我只是引用了错误的Excel应用程序对象。 Using the following statement returns the current Excel application and not a new one as I have implemented accidentially. 使用以下语句返回当前的Excel应用程序,而不是我偶然实现的新应用程序。

ExcelApp = Globals.ThisWorkbook.ThisApplication;

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

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