NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
DanB1983
Posts: 95
0 Kudos
Accepted Solution

Reading Data from an Excel File

Hi There,

 

I'm trying to use the attached VI (adapted from an example provided by someone else in a different thread) to read an Excel file.

 

It works well, apart from the fact that it leaves the file and Excel open when it has completed execution.

 

How would I close the file (and Excel) programmatically?

 

Many Thanks,

Dan

Dan
CLD
Active Participant Gak
Active Participant
Gak
Posts: 566

Re: Reading Data from an Excel File

try this.

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
Member
DanB1983
Posts: 95
0 Kudos

Re: Reading Data from an Excel File

Brilliant, thanks!

Dan
CLD
Member
Boazzz
Posts: 6
0 Kudos

Re: Reading Data from an Excel File

Thank you very much, it is almost exactly what i needed; I modified as i need and it works just fine.

 

Thanks !!!

Active Participant
RTSLVU
Posts: 567
0 Kudos

Re: Reading Data from an Excel File

[ Edited ]

Gak, I found your example today, and it looks like what I need too...

 

But it does not close Excel :smileysurprised:

 

The Application Quit is wired so I am using your example not the origonal post.

 

I am using Labview 2011 and Excel 2003 on Windows XP Profesional.

 

I made a quick "workaround" by setting it to run Excel hidden (Visible False) but it would be nice to have it actually close Excel.

 

I have to admit I know nothing about using these active-x methods.

Active Participant
RTSLVU
Posts: 567
0 Kudos

Re: Reading Data from an Excel File

More info to add:

 

The example returns the error:

 

Code 1045

 

Unknown System Error in ReadExcelTable[1].vi

Active Participant
RTSLVU
Posts: 567
0 Kudos

Re: Reading Data from an Excel File

[ Edited ]

I found a working example here: https://decibel.ni.com/content/docs/DOC-16042

 

This example extracts all of the data from the active cells of a worksheet.  The data is placed into an array where each element corresponds to the data in the same location of the Excel worksheet.

 

This can be usefull when all of the data needs to be extracted from a worksheet, but the amount of data in the worksheet is unknown.

Member
Newton2this
Posts: 118
0 Kudos

Re: Reading Data from an Excel File

Hi, can you point me to the previous thread you refer to here?  Also, I am trying to output the name of each sheet read from an Excel workbook.  Is there anyway to read/change the name of each Excel sheet from Sheet 1, Sheet 2, Sheet 3, to say Data Sheet 1, Data Sheet 2, Data Sheet 3,... in LabVIEW?  Basically, I just need to read the name of each Excel sheet from LabVIEW.  Thank you for your help!   

Active Participant nyc
Active Participant
Posts: 1,570
0 Kudos

Re: Reading Data from an Excel File


Newton2this wrote:

Hi, can you point me to the previous thread you refer to here?  Also, I am trying to output the name of each sheet read from an Excel workbook.  Is there anyway to read/change the name of each Excel sheet from Sheet 1, Sheet 2, Sheet 3, to say Data Sheet 1, Data Sheet 2, Data Sheet 3,... in LabVIEW?  Basically, I just need to read the name of each Excel sheet from LabVIEW.  Thank you for your help!   


There are examples that ship with LabVIEW on how to write to Excel and read from Excel. The examples use ActiveX automation.

 

You would have to expand upon those examples to get the names of the Excel worksheets and change their names. You would need to get the Sheets object of a Workbook. Then get the Item property of each of the Sheets. http://msdn.microsoft.com/en-us/library/bb259374%28v=office.12%29

Active Participant
ben64
Posts: 584
0 Kudos

Re: Reading Data from an Excel File

To add to nyc comment you can use the count property of the Sheets collection to set the count terminal of a FOR loop. You can then loop through all worksheets of the workbook and use their Name property to set or get their names. (NOTE: the index of the first worksheet is 1 so you need to add 1 to the loop index).

 

Ben64

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page