473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

COnverting CSV to XLS file

Hi,

I was wondering if one the smart people that frequent this group could
give me a hand with a small program I am attempting to debug.

I am not a highly experienced developer, but can create small
programs.

I was asked to write a small application that would look in a folder,
and convert all the CSV files to XLS.

I thought about using a macro, but they did not want that. Fine.

I wrote a small program in VB .NET (2003, I do nto have 2005 yet).

The program does the following:

For each select file in a list box
delete the existing XLS file, if there
Create a new Excel.Application

The source I used is as follows:
Private myExcelFile As Excel.Application (at the top of the file)

myExcelFile = New Excel.Application
xlConvert(oldFileName, newFilename)
The function called (xConvert) has the following:

******* begin source
Try

tFileNameCSV = MySrcPath + "\" + oldFileName
tFileNameXLS = MySrcPath + "\" + newFileName

' Open the CSV file
'myExcelFile = New Excel.Application
myExcelFile.Visible = False

myExcelFile.Workbooks.Open(MySrcPath + "\" + oldFileName)

'Turn off message box so that we do not get any messages
myExcelFile.DisplayAlerts = False

'Save the file as XLS file
myExcelFile.ActiveWorkbook.SaveAs(Filename:=MySrcP ath +
"\" + newFileName, FileFormat:=Excel.XlFileFormat.xlExcel9795,
CreateBackup:=False)

'Close the workbook
myExcelFile.ActiveWorkbook.Close(SaveChanges:=Fals e)

'Turn the messages back on
myExcelFile.DisplayAlerts = True

'Quit from Excel
myExcelFile.Quit()

'Kill the variable
myExcelFile = Nothing

******* end source

The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

André
Mar 20 '06 #1
5 10304
"Testguy" <te*****@magma.ca> schrieb
The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

You must explicitly release COM objects:

http://support.microsoft.com/kb/317109/en-us


Armin
Mar 20 '06 #2
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
"Testguy" <te*****@magma.ca> schrieb
The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

You must explicitly release COM objects:

http://support.microsoft.com/kb/317109/en-us


Armin


Mar 20 '06 #3
André,

Blows chunks? That sounds serious :)

Can you post the exception message and stack trace?

Brian

Testguy wrote:
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
"Testguy" <te*****@magma.ca> schrieb
The problem is that, as the files get converted, more an more memory
is being used (I am converting about 116 files right now).

Even after I close the executable, there is still a bunch of memory
being used.

Looking in the task manager, I could see at one time about 20 copies
of Excel.exe in memory.

After a while, it settles down to 11 copies in memory.

But I thought that, after quitting Excel and setting the variable to
"nothing", that this would free up my memory.

Any ideas as to what I am doing wrong?

Thank you in advance.

You must explicitly release COM objects:

http://support.microsoft.com/kb/317109/en-us


Armin


Mar 20 '06 #4
Hi Brian,

Okay. Blows chunks is a bit of an exageration.:-)

The try ... Catch takes care of that.

The message it generates is as follows (typos are mine):
System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Runtime.InteropServices.Marshal.ReleaseComO bject(Object o)
at SelectFolder.Form1.xlConvert(String oldFileName, String
newFileName) in <program name> : line 219
at SelectFolder.Form1.brnConmverttoXLS_Click(object sender, EventArgs
e) in <program name>: Line 173

Line 219 is the line with
System.Runtime.InteropServices.Marshal.ReleaseComO bject(myExcelFile)

Line 173 is the line that calls my function.

the variable myExcelFile is declared as follows:
Private myExcelFile As Excel.Application (a global variable)

The way I understand thing, I am told that the object or whatever that
I am releasing is not an object.

The following lines are what I got from the "Call stack" window:
SelectFolder.exe!SelectFolder.Form1.xlConvert(Stri ng oldFileName =
"1000ES_fieldlengths.csv", String newFileName =
"1000ES_fieldlengths.xls") Line 193 Basic
SelectFolder.exe!SelectFolder.Form1.btnConverttoXL S_Click(Object
sender = {System.Windows.Forms.Button}, System.EventArgs e =
{System.EventArgs}) Line 173 + 0x11 bytes Basic
[<Non-user Code>]
SelectFolder.exe!SelectFolder.Form1.Main() Line 4 + 0x1d bytes Basic
Not sure how to get Trace information. Sorry.

André

On 20 Mar 2006 12:48:33 -0800, "Brian Gideon" <br*********@yahoo.com>
wrote:
André,

Blows chunks? That sounds serious :)

Can you post the exception message and stack trace?

Brian

Testguy wrote:
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:
>"Testguy" <te*****@magma.ca> schrieb
>> The problem is that, as the files get converted, more an more memory
>> is being used (I am converting about 116 files right now).
>>
>> Even after I close the executable, there is still a bunch of memory
>> being used.
>>
>> Looking in the task manager, I could see at one time about 20 copies
>> of Excel.exe in memory.
>>
>> After a while, it settles down to 11 copies in memory.
>>
>> But I thought that, after quitting Excel and setting the variable to
>> "nothing", that this would free up my memory.
>>
>> Any ideas as to what I am doing wrong?
>>
>> Thank you in advance.
>
>
>You must explicitly release COM objects:
>
>http://support.microsoft.com/kb/317109/en-us
>
>
>
>
>Armin


Mar 20 '06 #5
Hi again,

I was playing with the program and, just for the hell, of it decided
to move my statements around.

my declaration for the "excel.application" variable is still a global.

But I moved the "myExcelFile = New Excel.Application" statement in the
subroutine "Form1_Load", and moved the statement "myExcelFile =
Nothing" in the subroutine "Form1_Closing" .

When running the application, Excel is opening once, and the problem
disappears.

Maybe the program was starting and stop the excel process so fast that
it could not deal with the memory issue.

I am confused. It now works properly, but I do not understand why I
previously had all these copy in Excel in memory.

Thanks for all the help.

André

On Mon, 20 Mar 2006 16:31:03 -0500, Testguy <te*****@magma.ca> wrote:
Hi Brian,

Okay. Blows chunks is a bit of an exageration.:-)

The try ... Catch takes care of that.

The message it generates is as follows (typos are mine):
System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Runtime.InteropServices.Marshal.ReleaseComO bject(Object o)
at SelectFolder.Form1.xlConvert(String oldFileName, String
newFileName) in <program name> : line 219
at SelectFolder.Form1.brnConmverttoXLS_Click(object sender, EventArgs
e) in <program name>: Line 173

Line 219 is the line with
System.Runtime.InteropServices.Marshal.ReleaseCom Object(myExcelFile)

Line 173 is the line that calls my function.

the variable myExcelFile is declared as follows:
Private myExcelFile As Excel.Application (a global variable)

The way I understand thing, I am told that the object or whatever that
I am releasing is not an object.

The following lines are what I got from the "Call stack" window:
SelectFolder.exe!SelectFolder.Form1.xlConvert(Str ing oldFileName =
"1000ES_fieldlengths.csv", String newFileName =
"1000ES_fieldlengths.xls") Line 193 Basic
SelectFolder.exe!SelectFolder.Form1.btnConverttoX LS_Click(Object
sender = {System.Windows.Forms.Button}, System.EventArgs e =
{System.EventArgs}) Line 173 + 0x11 bytes Basic
[<Non-user Code>]
SelectFolder.exe!SelectFolder.Form1.Main() Line 4 + 0x1d bytes Basic
Not sure how to get Trace information. Sorry.

André

On 20 Mar 2006 12:48:33 -0800, "Brian Gideon" <br*********@yahoo.com>
wrote:
André,

Blows chunks? That sounds serious :)

Can you post the exception message and stack trace?

Brian

Testguy wrote:
Thanks for the reply, Armin.

Alas, when I add the line mentioned in the web page, my program blows
chunks.

After doing the first conversion, it goes intot he CATCH, and stops
working.

André

On Mon, 20 Mar 2006 21:14:13 +0100, "Armin Zingler"
<az*******@freenet.de> wrote:

>"Testguy" <te*****@magma.ca> schrieb
>> The problem is that, as the files get converted, more an more memory
>> is being used (I am converting about 116 files right now).
>>
>> Even after I close the executable, there is still a bunch of memory
>> being used.
>>
>> Looking in the task manager, I could see at one time about 20 copies
>> of Excel.exe in memory.
>>
>> After a while, it settles down to 11 copies in memory.
>>
>> But I thought that, after quitting Excel and setting the variable to
>> "nothing", that this would free up my memory.
>>
>> Any ideas as to what I am doing wrong?
>>
>> Thank you in advance.
>
>
>You must explicitly release COM objects:
>
>http://support.microsoft.com/kb/317109/en-us
>
>
>
>
>Armin


Mar 21 '06 #6

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

Similar topics

1
by: david | last post by:
Hi there, Does anybody know of some restriction that stops the apache user on doing a dos2unix on a file upload from php? I'm getting 'permission denied' on some temp file that it tries to...
3
by: scoop_77 | last post by:
I'm looking for some software that would allow me to point to a folder in Windows Explorer, and have it output an html file with hyperlinks to all of the files within that folder and all of the...
4
by: mustafa | last post by:
Dear sir , I have built my application in visual basic 6.0 and crystal Report8.5 , Now i migrated my application to VB.net using the upgrade wizard.My visual basic form is upgraded to vb.net...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
3
by: Tim Marsden | last post by:
Hi, Given a file Path, for example "C:\Data\Samples". How do I convert this to "\\Server\Share\Data\Samples" The original "C:" , "F:" etc may be local or a mapped network drive. I am trying to...
4
by: VC | last post by:
Hi, Greetings. Not sure if this is the right forum..... In case I should visit some other forum please let me know. Does Dot.NET provide a quick method/way to convert a UNIX text file to DOS...
11
by: Gaurav Agarwal | last post by:
Hi All, Am looking for a python script that can convert fileformats to txt format. Am unable to find anything in python. Currently the InfoCon projects looks pretty good to use, but it is return...
11
by: juyi520 | last post by:
Hello, I am new in C in Programming, Where could I find the detail about struct FILE in RedHat Linux ? I have tried to check the stdio.h in /usr/include, but I could not find the
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
tracyyun
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...

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.