Hi all,
I wrote a small app, which could read text file and fill the data from
text file to a newly created excel file. It works fine on my computer,
but did not succeed on someone's. I caught an exception which told it
occurred when "trying to read or write protected memory. It usually
means the memory was damaged". What did I need to check? The account is
administrator, and it should be fine to write file at any place in that
PC.
Here is a my code. Thanks for any replying.
Excel.Applicati on ExcelObj = new
Microsoft.Offic e.Interop.Excel .Application();
void func1(string xlsfilename)
{
// See if the Excel Application Object was successfully constructed
if (ExcelObj == null)
{
MessageBox.Show ("ERROR: EXCEL couldn't be started!");
return;
}
try
{
string filename = xlsfilename;
Excel.Workbook wb = ExcelObj.Workbo oks.Add(Type.Mi ssing);
// get the collection of sheets in the workbook
Excel.Sheets sheets = wb.Worksheets;
Excel.Worksheet worksheet;
worksheet = (Excel.Workshee t)sheets.get_It em(1);
worksheet.Name = "Data";
//do some data processing
wb.SaveAs( filename , Type.Missing, Type.Missing, Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlSaveAsA ccessMode.xlNoC hange, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
wb.Close(false, Type.Missing, false);
}
catch(Exception ex)
{
MessageBox.Show ("Message: " + ex.Message + "\nSource: " + ex.Source
+ "\nTrack: "
+ ex.StackTrace);
}
ExcelObj.Workbo oks.Close();
ExcelObj.Quit() ;
ExcelObj = null;
GC.Collect();
} 1 8558
I just copied your code in to one of my apps and it works fine. The most
likely issue I could think of is a mismatch between the version of Excel
you're referencing in the IDE compared to the version you're executing
against.
Sorry I can't be more help.
Steve
"wasishinca r" <ad*********@gm ail.comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.com.. .
Hi all,
I wrote a small app, which could read text file and fill the data from
text file to a newly created excel file. It works fine on my computer,
but did not succeed on someone's. I caught an exception which told it
occurred when "trying to read or write protected memory. It usually
means the memory was damaged". What did I need to check? The account is
administrator, and it should be fine to write file at any place in that
PC.
Here is a my code. Thanks for any replying.
Excel.Applicati on ExcelObj = new
Microsoft.Offic e.Interop.Excel .Application();
void func1(string xlsfilename)
{
// See if the Excel Application Object was successfully constructed
if (ExcelObj == null)
{
MessageBox.Show ("ERROR: EXCEL couldn't be started!");
return;
}
try
{
string filename = xlsfilename;
Excel.Workbook wb = ExcelObj.Workbo oks.Add(Type.Mi ssing);
// get the collection of sheets in the workbook
Excel.Sheets sheets = wb.Worksheets;
Excel.Worksheet worksheet;
worksheet = (Excel.Workshee t)sheets.get_It em(1);
worksheet.Name = "Data";
//do some data processing
wb.SaveAs( filename , Type.Missing, Type.Missing, Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlSaveAsA ccessMode.xlNoC hange, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
wb.Close(false, Type.Missing, false);
}
catch(Exception ex)
{
MessageBox.Show ("Message: " + ex.Message + "\nSource: " + ex.Source
+ "\nTrack: "
+ ex.StackTrace);
}
ExcelObj.Workbo oks.Close();
ExcelObj.Quit() ;
ExcelObj = null;
GC.Collect();
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ST |
last post by:
Hi, I'm having problems opening up excel thru my code. It will write and
saveas an excel file, but the application won't open on the user's computer,
excel seems to be hidden, because it shows up on the task manager. The
problem is, if this user tries to download the data more than once, it gets
stuck because the file already exists, so I want it to overwrite the old
file...but the user can't overwrite when the excel app won't work! Any...
|
by: A frustrated developer |
last post by:
The following article discussed how to use the Excel, close and kill it:
http://support.microsoft.com/default.aspx?scid=kb;en-us;317109
But if you added a oBook.SaveAs(...) to save the workbook in the code, it
never worked for me. We use Excel 2003 and Visual Studio 2003 under Windows
XP. We don't have problem to kill Excel instance under Windows 2000, feels
like it is a new problem come with XP. I have been searching google for days...
|
by: mytfein |
last post by:
Hi Everyone,
Background:
Another department intends to ftp a .txt file from the mainframe, for me
to process.
The objective is to write a vb script that would be scheduled to run
daily to process this .txt file.
Goal:
I am working on a vba script to:
|
by: mail2atulmehta |
last post by:
Hi,
I do not know if this is right place for this, but i need some help. I
have a text file, whose values are seprated by a delimiter. I want to
open this file in excel, ( not import it) . I have written the driver
prg in c#. The code opens the file, but it is not writting the values
from text file into excel file. I can not figure out the problem here.
This is my code:
StreamReader dataFileReader = null;
FileInfo file = null;...
|
by: dgoel |
last post by:
Hi,
I Have a text file & I want to open it in excel sheet ( withou
importing). I have written code for it, but it is not opening exce
sheet. It opens the text file, but does not create a excel sheet
populate it. I do not know what the problem is, can someone please hel
out with this one,
Here is my code:
StreamReader dataFileReader = null;
FileInfo file = null;
Excel.Application ExcelObj = new Excel.Application();
| |
by: Agnes |
last post by:
Dim dsExcelExport As New System.Data.DataSet
Dim daExcelExport As New System.Data.SqlClient.SqlDataAdapter
Dim Excel As New Excel.Application
Dim strExcelFile As String
Dim strFileName As String
dsExcelExport.Clear()
daExcelExport.SelectCommand = New SqlCommand
daExcelExport.SelectCommand.Connection =
|
by: Coleen |
last post by:
Hi All :-)
I'm using .Net Framework 1.1, VB and need to be able to download the data
from a datagrid into an Excel 2000 spreadsheet for our accounting users.
Can anyone please point me to a good link on how to do this or give me some
pointers? TIA,
Coleen
|
by: =?Utf-8?B?QnJpYW5ESA==?= |
last post by:
Hi
Does anyone know of a way (via code behind) to pull a single sheet out of a
Excel workbook and convert it to a stand alone html document?
Thanks
Brian
|
by: DPK |
last post by:
Hello friends!!!
I made a prog. to make the excel. It is running well but when it saves the excel file it open the save dialog box to save the file. Becasue I am using SAVE function here instead of SAVEAS. So pls can anyone tell me how to use SAVEAS function in it. If I am using the function then I am getting Error and Error is:
so pls help me here: My code is below:
protected void Button1_Click(object sender, EventArgs e)
...
|
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 : oExcel.DisplayAlerts = False
|
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...
| |
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,...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |