<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="None">
  <name>Formatting Spreadsheet Strings</name>
  <metadata>
  <md:version>1.1</md:version>
  <md:created>2004/06/22 10:16:42 GMT-5</md:created>
  <md:revised>2004/07/16 15:26:27.923 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="lizzardg">
      <md:firstname>Elizabeth</md:firstname>
      
      <md:surname>Gregory</md:surname>
      <md:email>lizzardg@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mshiralkar05">
      <md:firstname>Malan</md:firstname>
      
      <md:surname>Shiralkar</md:surname>
      <md:email>mshiralkar05@hotmail.com</md:email>
    </md:maintainer>
    <md:maintainer id="harika">
      <md:firstname>Harika</md:firstname>
      
      <md:surname>Basana</md:surname>
      <md:email>ilsai@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>National Instruments</md:keyword>
    <md:keyword>LabVIEW</md:keyword>
    <md:keyword>spreadsheet</md:keyword>
    <md:keyword>string</md:keyword>
  </md:keywordlist>

  <md:abstract>In this lesson, you will learn how to format text files for use in spreadsheets.</md:abstract>
</metadata>

  <content>
    <para id="p1">
      To write data to a spreadsheet file, you must format the string
      as a spreadsheet string, which is a string that includes
      delimiters, such as tabs. In many spreadsheet applications, the
      tab character separates columns, and the end of line character
      separates rows.
    </para>
    <note>
      Use the end of line constant located on the <code>Functions&gt;&gt;All
      Functions&gt;&gt;String</code> palette to ensure portability of VIs
      among platforms. (<emphasis>Windows</emphasis>) The constant
      inserts a carriage return and a linefeed. (<emphasis>Mac
      OS</emphasis>) The constant inserts a carriage
      return. (<emphasis>UNIX</emphasis>) The constant inserts a
      linefeed.
    </note>
    <para id="p2">
      Use the <code>Write To Spreadsheet File</code> VI or the
      <code>Array To Spreadsheet String</code> function to convert a
      set of numbers from a graph, a chart, or an acquisition into a
      spreadsheet string. If you want to write numbers and text to a
      spreadsheet or word processing application, use the String
      functions and the Array functions to format the data and to
      combine the strings. Then write the data to a file.
    </para>
    <section id="s1">
      <name>Format Into File</name>
      <para id="s2p1">
	Use the <code>Format Into File</code> function to format
	string, numeric, path, and Boolean data as text and write the
	text to a file. Often you can use this function instead of
	separately formatting the string with the <code>Format Into
	String</code> function or<code> Build Text Express VI</code>
	and writing the resulting string with the <code>Write
	Characters To File VI</code> or <code>Write File</code>
	function.
      </para>
      <para id="s2p2">
	Use the <code>Format Into File</code> function to determine
	the order in which the data appears in the text file. However,
	you cannot use this function to append data to a file or
	overwrite existing data in a file. For these operations, use
	the <code>Format Into String</code> function with the
	<code>Write File</code> function. You can wire a
	<code>refnum</code> or <code>path</code> to the <code>input
	file</code> terminal of the <code>Format Into File</code>
	function, or you can leave this input unwired for a dialog box
	to prompt you for the filename.
      </para>
      <para id="s2p3">
	In the block diagram shown in <cnxn target="s2f1"/>, the
	<code>Open/Create/Replace File</code> VI opens a file, and the
	<code>For Loop</code> executes five times. The <code>Format
	Into File</code> function converts the iteration count and the
	random number to strings and places the tab and end of line
	characters in the correct positions to create two columns and
	one row in spreadsheet format. After the loop completes five
	iterations, the file closes, and the VI checks the error
	condition.
      </para>
      <figure id="s2f1">
	<media type="image/png" src="frmtspreadstrg.png"/>
      </figure>
      <para id="s2p4">
	This VI creates this text file, where an arrow (→)
	indicates a tab, and a paragraph symbol (¶) indicates an
	end of line character.
	<code type="block">
	  0→ 0.798141¶
	  1→ 0.659364¶
	  2→ 0.581409¶
	  3→ 0.526433¶
	  4→ 0.171062¶
	</code>
      </para>
      <para id="s2p5">
	You can open the previous text file in a spreadsheet
	application to display the spreadsheet shown in <cnxn target="s2f2"/>.
      </para>
      <figure id="s2f2">
	<media type="image/png" src="frmtspreadstrgxls.png"/>
      </figure>
    </section>
    <section id="s3">
      <name>Write LabVIEW Measurement File</name>
      <para id="s3p1">
	In the block diagram shown in <cnxn target="s3f1"/>, the
	<code>Write LabVIEW Measurement File</code> Express VI
	includes the open, write, close, and error handling
	functions. It also handles formatting the string with either a
	tab or comma delimiter. The <code>Merge Signals</code>
	function combines the iteration count and the random number
	into the dynamic data type.
      </para>
      <figure id="s3f1">
	<media type="image/png" src="frmtspreadstrg2.png"/>
      </figure>
      <para id="s3p2">
	The dialog box in <cnxn target="s3f2"/> shows the
	configuration for the <code>Write LabVIEW Measurement File</code>
	Express VI.
      </para>
      <figure id="s3f2">
	<media type="image/png" src="formatlvm.png"/>
      </figure>
      <para id="s3p3">
	This VI creates a <code>.lvm</code> file which you can open in
	a spreadsheet application. <cnxn target="s3f3"/> shows an
	example of the spreadsheet created by the previous
	configuration of the <code>Write LabVIEW Measurement File</code>
	Express VI.
      </para>
      <figure id="s3f3">
	<media type="image/png" src="frmtspreadstrgxls2.png"/>
      </figure>
      <para id="s3p4">
	Refer to the lesson on <cnxn document="m12258">Data Acquisition and
	Waveforms</cnxn>, for more information about the <code>Write
	LabVIEW Measurement File</code> and <code>Read LabVIEW
	Measurement File</code> Express VIs.
      </para>
    </section>



  </content>
  
</document>
