Preventing Excel from updating the screen in C#

倾然丶 夕夏残阳落幕 提交于 2020-01-15 03:26:13

问题


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?


回答1:


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;



来源:https://stackoverflow.com/questions/11002664/preventing-excel-from-updating-the-screen-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!