Answered by:
Problems using Excel Automation

Question
-
User1911411245 posted
I want to save an excel file in Server but i'm facing a problem.
I already waited for around 10 mins but still nothing happens (the browser process hang around 50%) and of course no file saved at the server.
This my code
Excel.ApplicationClass oAppClass = null; Excel.Workbook oWorkBook; Excel.Worksheet oWorkSheet; StringBuilder oSB = new StringBuilder();
try { oAppClass = new Excel.ApplicationClass(); oWorkBook = oAppClass.Workbooks.Open(filename, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); oWorkSheet = (Excel.Worksheet)oWorkBook.Sheets.get_Item(BranchCode); oAppClass.DisplayAlerts = false; oWorkSheet.Copy(Missing.Value, Missing.Value); //oWorkSheet.SaveAs(targetpath, // Missing.Value, Missing.Value, Missing.Value, Missing.Value, // Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); oAppClass.Save(targetpath); oAppClass.DisplayAlerts = true; } finally { oWorkSheet = null; oWorkBook = null; oAppClass.Quit(); oAppClass = null; GC.Collect(); }
FYI, I'm using Visual Studio 2005 (ASP.NET) and Excel 2007,
Please help, i already stucked with this problem >.<
Friday, August 15, 2008 6:00 AM
Answers
-
User1911411245 posted
Thanks for the quick reply.
But i already solved it myself, I use oWorkBook.SaveAs() to save the excel file and it works.
i don't really understand why oWorkBook.SaveAs() work and both oAppClass.Save() and oWorkSheet.SaveAs() don't work. Coz i don't fully understand about Excel Automation.
If u ask where it stucked i think when at oAppClass.Save()
Anyway.. thanks for the help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 16, 2008 12:23 PM
All replies
-
User-1811063981 posted
Hi
Where does the code get stuck? One thing I would try doing is to move
oAppClass.DisplayAlerts = false;
to right after you instantiated the object. After all, you're running it on the server, and not going to see any alerts anyways.
Also, you might want to consider using asynchronous operations:
http://msdn.microsoft.com/en-us/magazine/cc163725.aspx
Regards
Steve
Friday, August 15, 2008 10:12 AM -
User1911411245 posted
Thanks for the quick reply.
But i already solved it myself, I use oWorkBook.SaveAs() to save the excel file and it works.
i don't really understand why oWorkBook.SaveAs() work and both oAppClass.Save() and oWorkSheet.SaveAs() don't work. Coz i don't fully understand about Excel Automation.
If u ask where it stucked i think when at oAppClass.Save()
Anyway.. thanks for the help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 16, 2008 12:23 PM