LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Read data from excel file without converting a excel file into .csv or any other format

Hello,
Can somebody suggest me how to read from an excel file (consisting of 10 work sheets) to an array?
Thanks,
She
0 Kudos
Message 1 of 11
(5,013 Views)

Hi She,

Try search on 'excel' and 'activex'  I have posted a few examples how to read (directly) data from Excel with activex.

Let me know if it doesn't work.

0 Kudos
Message 2 of 11
(4,991 Views)
Hello,
it's right that you can use activeX. (For example with rhe report generation toolbox from ni) But there are some problems:
 
1. You have to have excel installed on the targed PC. (to get the ActiveX interface)
2. There exists different "Microsoft Excel x.x Object Library Version x.x" which have different methods and properties. If a costumer has an other version, it could be that it doesn't work.
3. You have to use LabVIEW 7.x an higher (LabVIEW 6.x doesn't close all references and you will get a memory leak)
Therefore I think its better (if possible) to use Spreadsheet-files. They can be opened with all versions of Excel and used without activeX in LabVIEW..
 
Ciao TPoint
Message 3 of 11
(4,988 Views)

You have to be careful when using the spreadsheet-files vi's.  They are located in the Functions Palette under File IO, you will find "Write To / Read From Spreadsheet File.vi"s. 

Here is what the Context Help says about the vi function:

"Reads a specified number of lines or rows from a numeric text file beginning at a specified character offset and converts the data to a 2D, single-precision array of numbers. You optionally can transpose the array. The VI opens the file before reading from it and closes it afterwards. You can use this VI to read a spreadsheet file saved in text format. This VI calls the Spreadsheet String to Array function to convert the data. "

This is quick & easy when the spreadsheet is all the same format.  You can set the format to string as well.  HOWEVER...  you do have to convert the Excel spreadsheet to text before using it.

I haven't experimented with the Active-X, but it may look as the way to go if you have combination text / numeric values in the spreadsheet.
 
If you did convert it to text, then you can use array functions as well and treating the file as an array of strings (see very brief example attached).  The example is to illustrate a point only 😉 
 
JLV
Message 4 of 11
(4,975 Views)
 
Yes, you must have Excel installed to read the data from Excel files with ActiveX. And it is correct that it will not always work with different windows/office releases.
But with the application where I used it it was a fine solution and it was used on several PC's.
Fill in the correct path with filename in the VI and all data will be available in the text array.
Message 5 of 11
(4,968 Views)
Hi K C,
I am trying to read some data from excel using Read Excel File.vi that you posted on 01-05-2006 08:05 AM and I get an error -2147417851 (source: The server threw an exception. in Read Excel File.vi).
I look inside the block diagram but simply changing the code (anything) gives me an error (for example changing the constant from true to false)
I am using LabView 7.1,Excel 2000 & WinXP
 
Thanks
-bm-
 
Message 6 of 11
(4,917 Views)

Hi,

Also with the VI you posted it works OK. I used this VI from LV5-Excel97 till now LV7.1-Excel2002.

You can try to select the your Excel application with right click on the Excel control.

Perhaps some else can try this VI with XP and Excel 2000

 

 

0 Kudos
Message 7 of 11
(4,907 Views)

This file worked for me (Read Excel File.vi).  I did get an error when I had it in a loop and called it frequently, it seems to take a while return data (likely to open the file in Excel, extract info and return).  Call it once and wait, all works well.

My system: Win2k, Office2003, Labview 7.0.

 

matt

0 Kudos
Message 8 of 11
(4,748 Views)
Although I was successful in using the Read Excel File VI (as well as different tabs), when I read entries that had dates in them (in the Excel forced format of 3/13/06), they are returned as large numbers (38876 for instance).  I tried to change the date format in Excel but it only accepts one (general) type.
 
What is this large number and is there a way to convert back to a date?
 
Thanks much - having Excel read capability will greatly increase how we use our data systems.
 
matt
0 Kudos
Message 9 of 11
(4,736 Views)

Yeah, that's what you get if you are talking to Microsoft  Smiley Tongue

Microsoft represent the date value as a integer of days since 30 dec 1899 Smiley Surprised

Can't help it. You need some nice calculation to retrieve a correct date.

Message Edited by K C on 03-01-2006 04:29 PM

0 Kudos
Message 10 of 11
(4,729 Views)