473,721 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can use C# to create and save excel file. But can't reopen the file as it crashes

Hi all,

Hope this is the right group.

I am writing a program in c# to open create an excel document, enter
some data, save it and then email it as an attachment. I have
successfully created an excel document which the user can see (at this
stage of development) and passed some data to it. I then used the
savas method to save the file. Again this seems to work as the file is
created. However once I close the excel file and try and reopen it
from the automatically saved version I get the following error
message, which results in it being impossible to open the excel doc.
This happens not just on my machine, but any computer that tries to
open these files.

Error message title bar reads as follows

Microsoft Excel – DebugMy Sheet.xls: Excel.EXE – Application Error

The body of the error message reads as follows

The instruction at "0x30004561 9" referenced memory at "0x00050018 ".
The memory could not be "read".
Click on OK to terminate the program
Click on Cancel to debug the program

I have research similar errors on Microsoft's site and have search
newsgroups. Although lots of people seem to get similar errors, they
seem to be caused by different situations and are not applicable to
what I am doing

I am using C# code and Excel 2000

I hope somebody has an answer

Here is my code
---------------------------------
//create excel file and data
Excel.Applicati on ExcelApp;
Excel._Workbook ExcelWorkbook;
Excel._Workshee t ExcelWorkSheet;

ExcelApp = new Excel.Applicati on();
ExcelApp.Visibl e = true;
ExcelWorkbook = (Excel._Workboo k)(ExcelApp.Wor kbooks.Add(
Missing.Value ));

ExcelWorkSheet = (Excel._Workshe et)ExcelWorkboo k.Sheets["Sheet1"];
ExcelWorkSheet. Name = "My Sheet";
//Make sure Excel is visible and give the user control
//of Microsoft Excel's lifetime.
ExcelApp.Visibl e = true;
ExcelApp.UserCo ntrol = true;
//text in cell
ExcelWorkSheet. Cells[1, 1] = "test sheet";
ExcelWorkSheet. Cells[3, 1] = "test1";
ExcelWorkSheet. Cells[3, 2] = "test2";
ExcelWorkSheet. Cells[3, 3] = "test3";
ExcelWorkSheet. Cells[3, 4] = "test4";
ExcelWorkSheet. Cells[3, 5] = "test5";
ExcelWorkSheet. Cells[3, 6] = " test6";

ExcelWorkSheet. get_Range("A3", "F3").Horizonta lAlignment =
Excel.XlHAlign. xlHAlignCenter;

ExcelWorkSheet. get_Range("A1", "A1").Font. Bold = true;
ExcelWorkSheet. get_Range("A3", "F3").EntireCol umn.AutoFit();
ExcelWorkSheet. get_Range("A3", F3").BorderArou nd(Excel.XlLine Style.xlContinu ous,Excel.XlBor derWeight.xlMed ium,
Excel.XlColorIn dex.xlColorInde xAutomatic,Exce l.XlColorIndex. xlColorIndexAut omatic);

ExcelWorkSheet. get_Range("E1", E1").Columns.En tireColumn.Numb erFormat =
"£###,###,##0.0 0";

string savepath;
savepath = Application.Exe cutablePath.ToS tring();
savepath = savepath.Substr ing(0,savepath. LastIndexOf("\\ "));
savepath = savepath + "\\TestExcelFil e.xls";

ExcelWorkbook.S aveAs(savepath, Excel.XlFileFor mat.xlCSV,Type. Missing,Type.Mi ssing,Type.Miss ing,
Type.Missing,Ex cel.XlSaveAsAcc essMode.xlNoCha nge,Type.Missin g,Type.Missing,
Type.Missing,Ty pe.Missing);

-------------------------------------
Thanks again

I Decker
Nov 15 '05 #1
0 41179

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3014
by: me | last post by:
I have a webpage containing a link to a spreadsheet <a href="somefilename.xls">click</a> When the link is clicked a spreadsheet opens in internet explorer using some sort of excel COM object. I would like to enable the user to edit the spreadsheet and then save the changes in the existing file. How ever IE only offers "save as" not "save" and it dosent suggest the original filename. The users already have write acces to the area where...
7
18795
by: Martin | last post by:
I have a situation where I'm displaying some information in a table on a web page. I've given the user the ability to make several different "queries" and show different sub-sets of the data. I would like to add a button to the page that would allow the user to create an .XLS file that would contain the current contents of the table. I realize that I could create it on the server and allow him to download it but I'd rather let him create...
1
11656
by: tkaleb | last post by:
I have to create output file in a text, MS Access, MS Excel and .dbf format from C# Win/ADO.NET application. Data are collected in DataSet and there is no problem to make text file. However, I have to create a new output files (tables with defined fields) in other 3 formats, and to fill them with data from DataSet. I created Excel output with ComponentOne's trial Excel component, but it is a temporary solution. Also I have unusual CP (1250...
1
2049
by: AMeador | last post by:
I need to have my c# application actually create a new Excel file from an Excel template file, and then update a bunch of fields in the new file. Can this be done? I am using VS.NET 2003 EA Edition and Excel 2003. Any pointers or sources would be greatly appreciated! Thanks!
4
1357
by: mattmerc | last post by:
Hi all, This is a repost from a week or so ago. I'll try to reformat so it is more clear. I am looking for something in asp .net / vb .net that will export a datagrid to Excel, BUT will save the file on the server (not the client). Can this be done without Excel installed on the server? Is there a was to send the contents of a datagrid as an excel
27
27402
by: jeniffer | last post by:
I need to create an excel file through a C program and then to populate it.How can it be done?
2
2231
by: RICHARD BROMBERG | last post by:
I wrote a small Access application that accepts a City Name and a Street Name and runs a Query based on them . I want to create an Excel Spread sheet that contains all the matches found by the Query. . Does anyone know how to do this . On a quick and dirty basis I was able to "cut and paste" the query results into an Excel Spread sheet. but thats a little too crude.
0
1386
by: Paul | last post by:
I have a web application that creates an xml file with app instructions set to excel. I noticed that I can not save a chart to an xml file so assuming I can not represent a chart in the xml file (to be opened by Excel). Just wondering if anyone knows if this will be supported in Office 2007? thanks. -- Paul G Software engineer.
0
1860
by: kennedystephen | last post by:
For the life of me, I cannot get this ... I have 1 excel document. I want to open that document and copy the first 50 rows to a new document. Then get the next 50 rows and copy those to a brand new document. I want to do this until the end of the Excel file. So... Open Excel1.
0
8840
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8730
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4484
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
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
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.