Connecting Tech Pros Worldwide Forums | Help | Site Map

C#, Excel Workbook, SaveAs doesn't work

Newbie
 
Join Date: Aug 2007
Posts: 4
#1: Aug 20 '07
Hi,
This is my first post on these forums and I am very new to c# and .Net, so please be gentle:)

I have an ASP application that is supposed to put data into a workbook and then save it and open it in the browser later on. The program seems to hang on the SaveAs(..) line, it sort of loads and loads and loads and nothing happens. Sometimes it eventually loads the start page of the application (session time out maybe?).

I was thinking that it might be something with permissions, but everything seems to be in place as far as i understand. This used to work 1-2 months ago, but we've recently installed MS Office 2007 on the server (we had 2003 before).

Any kind of ideas are appreciated, since i don't even know what to test anymore. An error message would have made things easier but i don't understand why i don't get one...

This is the code I have:
Expand|Select|Wrap|Line Numbers
  1. Excel.Application excelApp = new Excel.Application();
  2. excelApp.Visible = false;
  3.  
  4. System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture ; 
  5. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); 
  6.  
  7. excelApp.DisplayAlerts = false;
  8. Excel.Workbook eWorkbook = excelApp.Workbooks.Open(templateFolder+c.prodCode+".xls", 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);
  9.  
  10. this.fillTechDetails(eWorkbook, ds, c, templateFolder);
  11. this.fillTermsAndConditions(eWorkbook, c);
  12.  
  13. eWorkbook.SaveAs(fileFolder+c.ID+c.revision+".xls", Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Thanks in advance!
//Anna

kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Aug 20 '07

re: C#, Excel Workbook, SaveAs doesn't work


Welcome to TSDN. Suggest opening file in word 2007 to see if there is a problem. If it starts loading unlikely to be permissions. You say you are using ASP this may be the problem, try updating the code. HTH.
Newbie
 
Join Date: Aug 2007
Posts: 4
#3: Aug 21 '07

re: C#, Excel Workbook, SaveAs doesn't work


Thank you for you reply!
I have now managed to solve this problem by changing this

Expand|Select|Wrap|Line Numbers
  1. eWorkbook.SaveAs(fileFolder + c.ID + c.revision + ".xls", Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
to this:
Expand|Select|Wrap|Line Numbers
  1. eWorkbook.SaveAs(fileFolder + c.ID + c.revision + ".xls", Excel.XlFileFormat.xlXMLSpreadsheet, Type.Missing, Type.Missing, false, false, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
I'm not sure why it worked but it worked! :)

Quote:

Originally Posted by kenobewan

Welcome to TSDN. Suggest opening file in word 2007 to see if there is a problem. If it starts loading unlikely to be permissions. You say you are using ASP this may be the problem, try updating the code. HTH.

Newbie
 
Join Date: Jun 2009
Location: Karachi Pakistan
Posts: 2
#4: Oct 7 '09

re: C#, Excel Workbook, SaveAs doesn't work


Well Thanks ......
This helped me a lot. I was also having the same issue.

Majid
-------------------------------------------------------------------------------------

Quote:

Originally Posted by girlswannahavefun View Post

Thank you for you reply!
I have now managed to solve this problem by changing this

Expand|Select|Wrap|Line Numbers
  1. eWorkbook.SaveAs(fileFolder + c.ID + c.revision + ".xls", Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
to this:
Expand|Select|Wrap|Line Numbers
  1. eWorkbook.SaveAs(fileFolder + c.ID + c.revision + ".xls", Excel.XlFileFormat.xlXMLSpreadsheet, Type.Missing, Type.Missing, false, false, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
I'm not sure why it worked but it worked! :)

Reply