utunga
02-25-2004, 10:06 PM
We have an application need to delivering fairly significant amounts of financial data from our web server into excel. We will need to do a lot of filtering/sorting of this data before/once it arrives, and the natural choice for end users is to have the data reports show up in Excel.
One way to do this is via .NET WinForms application that runs on local desktop, loads data via webservices from the webserver, based on the users’ choices (made in the rich WinForms environment) and then connects to Excel and writes out the data.
The other choice is to use Excel VBA to talk directly to the webservices layer (web services calls via VB Subs approach).
I would prefer the first option, for various reasons, but am very concerned about performance.
Just as a test, I set up the following code (below). All the relevant Excel 10.0 assembly references are there. (The code works), referenced functions do the obvious thing.
The problem is, even though I am only updating 20x20=400 cells the code takes 10 Seconds to run !!
What on earth could be going wrong here? More to the point is there another way to dump data from C# to Excel that is a bit more efficient??
If not, we will have to dump this approach and go with Excel VBA, because we are going to need to update thousands of rows at a time.
Thanks in advance for your help..ExcelApp.ScreenUpdating = false;
int TEST_ROWS=20;
int TEST_COLS=20;
for (int i = 1; i < TEST_ROWS; i++)
{
for (int j = 0; j < TEST_COLS; j++)
{
Excel.Range theRange = TheSheet.Cells.get_Range(GetExcelIndexToLetter(j) + (i + 1).ToString(),
GetExcelIndexToLetter(j) + (i + 1).ToString());
theRange.Value2 = "test";
}
}
ExcelApp.ScreenUpdating = true;
One way to do this is via .NET WinForms application that runs on local desktop, loads data via webservices from the webserver, based on the users’ choices (made in the rich WinForms environment) and then connects to Excel and writes out the data.
The other choice is to use Excel VBA to talk directly to the webservices layer (web services calls via VB Subs approach).
I would prefer the first option, for various reasons, but am very concerned about performance.
Just as a test, I set up the following code (below). All the relevant Excel 10.0 assembly references are there. (The code works), referenced functions do the obvious thing.
The problem is, even though I am only updating 20x20=400 cells the code takes 10 Seconds to run !!
What on earth could be going wrong here? More to the point is there another way to dump data from C# to Excel that is a bit more efficient??
If not, we will have to dump this approach and go with Excel VBA, because we are going to need to update thousands of rows at a time.
Thanks in advance for your help..ExcelApp.ScreenUpdating = false;
int TEST_ROWS=20;
int TEST_COLS=20;
for (int i = 1; i < TEST_ROWS; i++)
{
for (int j = 0; j < TEST_COLS; j++)
{
Excel.Range theRange = TheSheet.Cells.get_Range(GetExcelIndexToLetter(j) + (i + 1).ToString(),
GetExcelIndexToLetter(j) + (i + 1).ToString());
theRange.Value2 = "test";
}
}
ExcelApp.ScreenUpdating = true;