473,587 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#, Excel Workbook, SaveAs doesn't work

4 New Member
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
Aug 20 '07 #1
3 31275
kenobewan
4,871 Recognized Expert Specialist
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.
Aug 20 '07 #2
girlswannahavefun
4 New Member
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! :)

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.
Aug 21 '07 #3
majidkorai
6 New Member
Well Thanks ......
This helped me a lot. I was also having the same issue.

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

@girlswannahavef un
Oct 7 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
25250
by: Geert-Pieter Hof | last post by:
Hello, My VB 6.0 application read and writes data from and to a MS Excel workbook, using the Microsoft.Jet.OLEDB.4.0 provider. Now I want to protect the Excel workbook with a password, but I figured out that it is not possible to open the workbook for data access with ADO (http://support.microsoft.com/?KBID=211378). Is there another...
7
4089
by: Pierre | last post by:
Hi, Tryin to use this method : MyExcelObject.Application.ActiveWorkBook.set_Colors(int index, object RHS). But really don't know what this RHS is ? Any ideas ? Thks for help
1
3063
by: Axel | last post by:
Hi! I need to convert a stream containing an Excel workbook to an Excel ..csv file but I am not really getting it to work. Just saving the stream as abc.xls is no good so I guess I need to create a workbook and load it with the stream, but here ends my knowledge about this... Just opening the workbook as a file and convert it is no...
1
2281
by: JM | last post by:
Hi I was wondering if anyone out there knew how to give a Excel workbook focus. Problem is that if I go away and do work on something else e.g. E-Mail while the C# program is dropping data into Excel that it will miss data. How do I give the Excel workbook focus so that it will drop the data in and not go into limbo land? A web address or...
1
2134
by: | last post by:
The following code: Private Sub ClearControls(ByVal ctrl As Control) Dim i As Int32 For i = ctrl.Controls.Count - 1 To 0 Step -1 ClearControls(ctrl.Controls(i))
1
3811
by: Jerry J | last post by:
I am sending Excel reports to web clients. Excel opens in internet explorer displaying multiple sheets. It is pretty simple to do and works well. To do it, a client clicks a link to an ASPX page that first generates Excel.htm files (query string contains parameters for the specific reports) then uses Response.Write() to stream and Excel...
5
8031
by: Iris | last post by:
I have 8 text files (tab delimited) that I would like to import into an Excel workbook as 8 individual worksheets but I cannot find any example code on this subject. Can anyone help me please???? Thanks in advance. Regards,
2
5956
by: k-w | last post by:
Hi all In vb I do: Dim Ex As New Excel.Application Ex.Workbooks.Open "c:\tmp\Book1.xls" Similar code in VC doesn't work:
3
6217
by: =?Utf-8?B?Um9k?= | last post by:
The applicacion sends me the next message "Method not found: Excel._Worksheet.SaveAs (..." I thinks that its about permissions but I do not know how to fix it. I have the same source in two different servers, It work in one of these but it doesn's work in the second one. oExcel = New Excel.Application oExcel.Visible = False :...
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.