LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Data from an Excel File

Solved!
Go to solution

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
0 Kudos
Message 1 of 17
(7,513 Views)
Solution
Accepted by topic author DanB1983

try this.

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
Message 2 of 17
(7,510 Views)

Brilliant, thanks!

Dan
CLD
0 Kudos
Message 3 of 17
(7,508 Views)

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

 

Thanks !!!

0 Kudos
Message 4 of 17
(7,330 Views)

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

 

But it does not close Excel Smiley Surprised

 

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 17
(7,267 Views)

More info to add:

 

The example returns the error:

 

Code 1045

 

Unknown System Error in ReadExcelTable[1].vi

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 17
(7,263 Views)

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 17
(7,238 Views)

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!   

0 Kudos
Message 8 of 17
(7,071 Views)

@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

0 Kudos
Message 9 of 17
(7,063 Views)

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

0 Kudos
Message 10 of 17
(7,056 Views)