473,602 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Applicati on

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

myExcelFile = New Excel.Applicati on
xlConvert(oldFi leName, newFilename)
The function called (xConvert) has the following:

******* begin source
Try

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

' Open the CSV file
'myExcelFile = New Excel.Applicati on
myExcelFile.Vis ible = False

myExcelFile.Wor kbooks.Open(MyS rcPath + "\" + oldFileName)

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

'Save the file as XLS file
myExcelFile.Act iveWorkbook.Sav eAs(Filename:=M ySrcPath +
"\" + newFileName, FileFormat:=Exc el.XlFileFormat .xlExcel9795,
CreateBackup:=F alse)

'Close the workbook
myExcelFile.Act iveWorkbook.Clo se(SaveChanges: =False)

'Turn the messages back on
myExcelFile.Dis playAlerts = True

'Quit from Excel
myExcelFile.Qui t()

'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 10316
"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*******@free net.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*******@free net.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.NullRefe renceException: Object reference not set to an instance
of an object.
at System.Runtime. InteropServices .Marshal.Releas eComObject(Obje ct o)
at SelectFolder.Fo rm1.xlConvert(S tring oldFileName, String
newFileName) in <program name> : line 219
at SelectFolder.Fo rm1.brnConmvert toXLS_Click(obj ect sender, EventArgs
e) in <program name>: Line 173

Line 219 is the line with
System.Runtime. InteropServices .Marshal.Releas eComObject(myEx celFile)

Line 173 is the line that calls my function.

the variable myExcelFile is declared as follows:
Private myExcelFile As Excel.Applicati on (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.ex e!SelectFolder. Form1.xlConvert (String oldFileName =
"1000ES_fieldle ngths.csv", String newFileName =
"1000ES_fieldle ngths.xls") Line 193 Basic
SelectFolder.ex e!SelectFolder. Form1.btnConver ttoXLS_Click(Ob ject
sender = {System.Windows .Forms.Button}, System.EventArg s e =
{System.EventAr gs}) Line 173 + 0x11 bytes Basic
[<Non-user Code>]
SelectFolder.ex e!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*********@ya hoo.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*******@free net.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.applicat ion" variable is still a global.

But I moved the "myExcelFil e = New Excel.Applicati on" statement in the
subroutine "Form1_Load ", and moved the statement "myExcelFil e =
Nothing" in the subroutine "Form1_Clos ing" .

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.NullRef erenceException : Object reference not set to an instance
of an object.
at System.Runtime. InteropServices .Marshal.Releas eComObject(Obje ct o)
at SelectFolder.Fo rm1.xlConvert(S tring oldFileName, String
newFileName) in <program name> : line 219
at SelectFolder.Fo rm1.brnConmvert toXLS_Click(obj ect sender, EventArgs
e) in <program name>: Line 173

Line 219 is the line with
System.Runtime .InteropService s.Marshal.Relea seComObject(myE xcelFile)

Line 173 is the line that calls my function.

the variable myExcelFile is declared as follows:
Private myExcelFile As Excel.Applicati on (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.e xe!SelectFolder .Form1.xlConver t(String oldFileName =
"1000ES_fieldl engths.csv", String newFileName =
"1000ES_fieldl engths.xls") Line 193 Basic
SelectFolder.e xe!SelectFolder .Form1.btnConve rttoXLS_Click(O bject
sender = {System.Windows .Forms.Button}, System.EventArg s e =
{System.EventA rgs}) Line 173 + 0x11 bytes Basic
[<Non-user Code>]
SelectFolder.e xe!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*********@ya hoo.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*******@free net.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
13117
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 create. I tried doing it from the command line by manually placing a fake upload file in /tmp: $ ls -ltr /tmp
3
6145
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 sub-folders. I have many folders with several dozen files and sub-folders and would like to avoid hand-coding all of the hyperlinks. Does anyone know if such software exists? Thanks in advance.
4
2470
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 but my .dsr file that i created using crystalReport is not migrated , when i try to convert it into .rpt file using add new item in Vb.net Envs it give me the error in the log file saying,
0
3924
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
5
2510
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 applications. I am testing an upgrade of all of the sites and have converted the main root site...although not necessarily fixed any issues. I move on instead and converted one of the virtual roots that is a seperate
3
1272
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 ensure the path (stored as sting in database) is valid from any machine, regardless of the drive mappings and shares on the machine. any suggestions, Tim
4
2331
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 format? Cheers!!! V
11
4633
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 in java. Thanks and Regards, Gaurav Agarwal
11
4764
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
7993
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
7920
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
8401
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
8404
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
8054
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
8268
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 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...
0
6730
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
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();...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.