L
Linan
Recently I wrote a program to help my wife to extract data from about
500 excel files. For each file, around 1000 cells are visited and the
texts are retrieved.
Firstly I wrote a python script, used win32com module. The program ran
well, but took 78 mins to accomplished the task. Of course it was a
little bit slow, so I gave csharp a go. The csharp program took 72
mins.
Both Excel and .Net are MS product, run on a microsoft operating
system. However, I don't see any performance advantages. I don't want
to fire a script/compile laugange or opensource/ms war. My question is,
any tricks to speed COM related operation up in csharp, without using
multiple threading?
My code:
<pre>
Application excelApp=new Application();
// Go through 500+ excel files
foreach(string file in fileList){
excelApp.Workbooks.Open(file,Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
// Go through 1000+ cells in each file
foreach(DictionaryEntry de in cellHash){
string id=(string)de.Key;
string[] val=(string[])de.Value;
string
v=(string)excelApp.Sheet[val[1]].get_Range(val[0],Missing.Value).Text;
Console.WriteLine("{0}\t{1}\t{2}\t{3}",id,day,time,v);
}
excelApp.Workbooks.Close();
}
</pre>
500 excel files. For each file, around 1000 cells are visited and the
texts are retrieved.
Firstly I wrote a python script, used win32com module. The program ran
well, but took 78 mins to accomplished the task. Of course it was a
little bit slow, so I gave csharp a go. The csharp program took 72
mins.
Both Excel and .Net are MS product, run on a microsoft operating
system. However, I don't see any performance advantages. I don't want
to fire a script/compile laugange or opensource/ms war. My question is,
any tricks to speed COM related operation up in csharp, without using
multiple threading?
My code:
<pre>
Application excelApp=new Application();
// Go through 500+ excel files
foreach(string file in fileList){
excelApp.Workbooks.Open(file,Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
// Go through 1000+ cells in each file
foreach(DictionaryEntry de in cellHash){
string id=(string)de.Key;
string[] val=(string[])de.Value;
string
v=(string)excelApp.Sheet[val[1]].get_Range(val[0],Missing.Value).Text;
Console.WriteLine("{0}\t{1}\t{2}\t{3}",id,day,time,v);
}
excelApp.Workbooks.Close();
}
</pre>