防止Excel更新C#中的屏幕 [英] Preventing Excel from updating the screen in C#

查看:214
本文介绍了防止Excel更新C#中的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Excel 2010编写VIsual C#中的一个加载项。此加载项从我们的服务中检索一些数据,并将结果写入某个电子表格的单元格。但是,我不希望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仍然显示正在写入的所有单元格。我做错了什么?

解决方案

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



ExcelApp = Globals.ThisWorkbook.ThisApplication; / code>


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. However I don't want Excel to display filling the cells with values as this takes a lot of time. 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:

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

Unfortunately Excel still displays all of the cells being written. What am I doing wrong?

解决方案

I just referenced the wrong Excel application object. Using the following statement returns the current Excel application and not a new one as I have implemented accidentially.

ExcelApp = Globals.ThisWorkbook.ThisApplication;

这篇关于防止Excel更新C#中的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆