Вы находитесь на странице: 1из 5

LabVIEW Technical Resource – tools and techniques

Bridging the Gap Between LabVIEW and Excel


Using the XL-VIEW Toolkit
by Eric Mallett

How often has your customer or For comparison, let’s examine a simple your customer’s satisfaction. By
manager requested presentation quality quality checking and reporting data replacing the Write to Spreadsheet VIs
graphs and data tables from your acquisition program. The block diagram with a few simple Excel communication
LabVIEW applications? LabVIEW, shown in Figure 1 outputs a plain page VIs, your data will look more
though brilliant in other ways, has of numbers or a text file that is really professional (see Figure 3b).
limited capabilities for generating quite basic . Your customer now has the
formatted output, making it difficult to data, but not in a very useful format, Often, the data is not simply composed
create data presentations which meet a unless you first import the file into Excel of numeric data. How frequently do you
customer or manager’s expectations. and then format it. Reformatting an need a column representing time

Figure 1: Writing ASCII data files

Up until now, a typical method for imported text file in Excel can be time occurrences? The data formatting VI
generating formatted output was to save consuming, especially since Excel tends reformats the first column to reflect the
simple tab-delimited ASCII text files, to break up header information. time of day. You will also want to format
and later import those files into Excel to the rest of the data table. Additionally,
manually create formatted data tables Writing Formatted Excel Files the formatting VIs give you access to
and graphs. There is a new toolkit avail- from LabVIEW Excel’s “format>>cells” pull-down menu
able which will cut out this extra step and The block diagram shown in Figure 2 of data type formatting options. The
have your LabVIEW programs talk illustrates how to output formatted data Name Sheet.vi assigns meaningful names
directly to Excel using ActiveX. The new more efficiently by eliminating the text to each work or chart sheet.
toolkit, XL-VIEW, allows you to bridge file writing VIs and sending
the gap between LabVIEW and Excel, your data directly to Excel.
giving you the best of both worlds. The new toolkit of VIs called
XL-VIEW makes it easy to
This modular package of VIs allows automate this process.
your programs to create formatted data Adding borders, bold or italic
tables and graphs ready for use by your fonts, or even some color and
manager or customer. XL-VIEW lets data alignment will make
you easily take advantage of the data the table easier to read.
formatting power of Excel from Yes, the program has grown
within LabVIEW. (see Figure 3a), but so has Figure 2: Writing Excel files using XL-VIEW

LabVIEW Technical Resource • Volume 7, Number 2 • www.ltrpub.com



LabVIEW Technical Resource – tools and techniques

Figure 3a: Using XL-VIEW to format an Excel data Table

Creating Excel Graphs Additionally, you can format the legend,


from LabVIEW plot area, graph title and much more
Graphs enhance the look of a data (see Figure 4a and 4b).
presentation, making it easier to compre-
hend. We’ve seen great improvements in Printing Excel Output Figure 3b: XL-VIEW format results
LabVIEW’s printing abilities with the from LabVIEW
release of 5.1; however, Excel is currently Now that your data is presentable and
more powerful in this area. The stored in a form specifically created for can apply descriptive headers and footers,
XL-VIEW VIs allow you to take full data manipulation, you still need to page numbers, the date, and can also

Figure 4a: Using XL-VIEW to format graph axes, legend, title


and other advanced Excel Graph Wizard features Voltage Drop

advantage of Excel’s graphing capabilities create a hard copy of the table and graph.
from within your LabVIEW programs. If There is no need to open Excel, the
you only need to build a simple graph, Print.vi in XL-VIEW will print the graph
use XL-VIEW’s Easy Graph.vi. However, and data for you directly from within
if you want direct control over the Excel your LabVIEW program.
Graph Wizard steps, you have that flexi-
bility, too. Having full access to the Before your program directs Excel to
Graph Wizard allows you to label axes, print, you’ll want to format the output
apply gridlines and modify scaling. pages. Using XL-VIEW, your application Figure 4b: XL-VIEW graph results

www.ltrpub.com • Volume 7, Number 2 • LabVIEW Technical Resource



LabVIEW Technical Resource – tools and techniques

Using Excel Formulas in


LabVIEW Output Files
Have you ever needed to make
calculations on a table similar to the pre-
vious example shown in Figure 3b on
page 15? What if your customer wants
to know the average voltage measured
per quarter-hour during the shift? How
would you determine this? If you are
Figure 5: Controlling Excel’s page setup and printing
using a text file, you have two options.
The first option is to sum and store the
numbers of each measurement
scale your print-out and adjust the of Excel’s Page Setup process, then you determined throughout the shift, then
margins as shown in Figure 5. If it is part now have control over it from LabVIEW. average and write the results at the end of

Figure 6: Writing three averaging equations and three IF statements

the shift. The second option is to write


the voltage measurements to file during
Voltage Drop each interval; and at the end of the shift,
read the entire data table; calculate
average values, and write the results.
Both are workable solutions if the data
sets are small.

However, a better solution is to store


your data in Excel and take advantage
of its calculation abilities. Figure 6
demonstrates how to solve this problem
using XL-VIEW. Write the observed
voltages using the XL-VIEW VIs, as
shown previously, then use XL-VIEW’s
equation building VIs to construct the
averaging formula and write to
whichever cell you wish. The formula
can even be written to another
worksheet. If you also need to know if
the average was greater than normal, use
the Logic, Comparison and IF Statement
Figure 7: Example results using the XL-VIEW toolkit VIs to construct an Excel formula and

LabVIEW Technical Resource • Volume 7, Number 2 • www.ltrpub.com



LabVIEW Technical Resource – tools and techniques

include the answer as part of the data illustrated previously in Figure 6. All if you had been maintaining this data set
table. A pie chart of the averages would equation building VIs have inputs for within Excel and written the equations to
clearly indicate which voltage is highest. both the A1 and row-column formats. perform the calculations, you need only
You can create a pie chart with the graph read a single cell of data after making the
VIs just as you did with the data table. Using Excel Calculations needed changes. Consider the example of
Compare the report you were able to to Access and Maintain a 100 row by 100 column data set. You
create programmatically with the LabVIEW Data want to change the value in row 51 and
XL-VIEW toolkit (see Figure 7) and Many applications require maintenance column 10, and then recalculate the
the text file you produced without it of a large data set, however, what is really overall mean. With a text data file, you
(see Figure 1) to see the ease of using of interest are calculations made from a would read the entire data set, use the
XL-VIEW to automate the task. portion of the data set and how changes array functions to replace the value of
to one or more specific values alter the interest, calculate the overall mean, and
Constructing Excel Equations in results of these calculations. Using text rewrite the entire data file. With an Excel
LabVIEW Output Files files to perform these tasks in LabVIEW data file, you write the new value to cell
XL-VIEW’s Logic, Comparison, and is very difficult. You cannot easily read or J51 (row 51, column 10) and read the
Mathematics VIs provide the flexibility write a specific value from an ASCII file, overall mean from cell CV101 (row 101,
to construct any formula that can be cre- nor can you read, for example, the column 100). This is possible because
ated when working in Excel. Only one middle 200 observations from the when you created the data set, you wrote
VI is required to send your equations fifteenth column of data without signifi- the equation “sum(A1:CV100)” to cell
from LabVIEW to the cell or group of cant effort. If the data were saved in CV101. Even if the equation had not
cells you choose. For example, let’s Excel, then your LabVIEW program can been setup previously, you could still add
construct the equation easily access the data using XL-VIEW. the equation at any time to the data set
Simply open the existing data set, specify using the XL-VIEW VIs.
the sheet and range of cells you are inter-
ested in, and you have direct access to the About XL-VIEW
information stored in these locations. The XL-VIEW toolkit generates format-
The block diagram shown in Figure 8 The power of this capability becomes ted LabVIEW output by having your
does this quite easily. Notice how the B4 even more evident when you need to LabVIEW programs talk directly to
term is added. The cell is specified by the determine the effects of changing Excel using ActiveX. Because the
XL-VIEW VIs use the ActiveX
technology, the toolkit is only available
for Windows NT/98/95 users.

Not only does this toolkit expand


LabVIEW’s data output formatting
abilities. Additionally, this toolkit makes
SQUARE ROOT
LabVIEW much more attractive to
Measure users considering an upgrade to
LabVIEW, since any templates they have
created can now be accessed with ease.

A demo of the XL-VIEW toolkit for


Windows NT/98/95 users is included on
this issue’s LTR resource disk.
Figure 8: Building a formula in A1 Format
About the author:

Eric Mallett is President of E&L Software Solutions, the


row and column numbers, not by the information within these cells. If you developers of the XL-VIEW toolkit. XL-VIEW can be
string “B4”. Using row-column format have been able to change individual obtained from E & L Software Solutions either online
allows you to write the same equation to values in a text file from LabVIEW, recal- at members.aol.com/ELSSsales or by telephone at
multiple cells and to increment the cells culating values of interest still requires 480-807-3873 (country code 01).
within the equation. This concept was you to read the entire data set. However,

www.ltrpub.com • Volume 7, Number 2 • LabVIEW Technical Resource


order
the only labview subscription with vi software included form
WHAT IS LTR?
T E L : 214 - 7 0 6 - 0 5 8 7 FA X : 2 1 4 - 7 0 6 - 0 5 0 6
LabVIEW Technical
Resource (LTR) is a
quarterly journal for
LabVIEW users and contact information
developers available by
subscription from LTR
Publishing, Inc. Each LTR Name _______________________________________________ Company ____________________________________
issue presents powerful Address_____________________________________________________________________________________________
LabVIEW tips and tech-
niques and includes a City ___________________________ State______________________ Zip/Post Code__________ Country____________
resource disk packed with VI Tel (required) ______________________ FAX ______________________ E-mail ____________________________________
source code, utilities, and
documentation. Technical
articles on LabVIEW pro-
gramming methodology,
order information
in-depth tutorials, and time-
saving tips and techniques QTY WIN/MAC PRODUCT U.S. INTL. EXTENDED PRICE
address everyday program-
ming issues in LabVIEW. 1 year subscription (4 issues / 4 diskettes) $95 $120

In its seventh year of publi- 2 year subscription (8 issues / 8 diskettes) $175 $215
cation, LTR has subscribers CD library of back issues Ver 2.0 (20 issues / over 150 VIs) $325 $350
in over 45 countries and is
well-known as a leading Upgrade CD toVersion 2.0 (requires version 1.0) $89 $99
independent source of
LabVIEW-specific Back issues – [Article Index available at www.ltrpub.com] $25 $30
information.
SUBTOTAL
Download sample issue at www.ltrpub.com
Purchase the LabVIEW
TX TAX @ 8.25%
Technical Resource
CD-ROM Library of Back TOTAL
Issues Version 2.0 and
browse this searchable payment information
CD-ROM for easy access to
over 150 articles and VIs
from LTR Vol I-VI. ✔ PAYMENT METHOD

Check enclosed (U.S. BANK ONLY* – Make check payable to LTR Publishing) (Texas residents please add 8.25% sales tax)
To subscribe to the
LabVIEW Technical Bill company (U.S. Only) / P.O. number required
Resource or to order the
CD-ROM Library of Back Visa / MC Card Number Exp.
Issues, fax this form to Signature
LTR Publishing at
(214) 706-0506 or visit * Wire information available for international orders
the LTR web page at
www.ltrpub.com to Fill out the form above and Fax it to: 214-706-0506 with your credit card information and signature,
download a free OR send the completed order form with U.S. check to:
sample issue. LTR Publishing, Inc., 6060 N. Central Expressway, Suite 502, Dallas,Texas 75206

You may also include your own Federal Express or Airborne #. If you are ordering
a product for delivery within Texas, please include Texas Sales Tax at 8.25%.

Copyright © 1999 LTR Publishing, Inc. All rights reserved. LabVIEW Technical Resource is an independently produced publication of LTR Publishing, Inc.
LabVIEW is a registered trademark of National Instruments Corporation.

w w w . lt r p u b . c o m