The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<HTML>
<HEAD>
<TITLE>Spreadsheet::BasicRead - Methods to easily read data from spreadsheets</TITLE>
<LINK REV="made" HREF="mailto:">
</HEAD>

<BODY>

<A NAME="__index__"></A>
<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#name">NAME</A></LI>
	<LI><A HREF="#description">DESCRIPTION</A></LI>
	<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
	<LI><A HREF="#required modules">REQUIRED MODULES</A></LI>
	<LI><A HREF="#methods">METHODS</A></LI>
	<UL>

		<LI><A HREF="#new">new</A></LI>
		<LI><A HREF="#getnextrow()"><CODE>getNextRow()</CODE></A></LI>
		<LI><A HREF="#numsheets()"><CODE>numSheets()</CODE></A></LI>
		<LI><A HREF="#openspreadsheet(filename)"><CODE>openSpreadsheet(fileName)</CODE></A></LI>
		<LI><A HREF="#currentsheetnum()"><CODE>currentSheetNum()</CODE></A></LI>
		<LI><A HREF="#currentsheetname()"><CODE>currentSheetName()</CODE></A></LI>
		<LI><A HREF="#setcurrentsheetnum(num)"><CODE>setCurrentSheetNum(num)</CODE></A></LI>
		<LI><A HREF="#getnextsheet()"><CODE>getNextSheet()</CODE></A></LI>
		<LI><A HREF="#getfirstsheet()"><CODE>getFirstSheet()</CODE></A></LI>
		<LI><A HREF="#cellvalue(row, col)">cellValue(row, col)</A></LI>
		<LI><A HREF="#getfirstrow()"><CODE>getFirstRow()</CODE></A></LI>
		<LI><A HREF="#setheadingrow(rownumber)"><CODE>setHeadingRow(rowNumber)</CODE></A></LI>
		<LI><A HREF="#setrow(rownumber)"><CODE>setRow(rowNumber)</CODE></A></LI>
		<LI><A HREF="#getrownumber()"><CODE>getRowNumber()</CODE></A></LI>
		<LI><A HREF="#logexp(message)"><CODE>logexp(message)</CODE></A></LI>
		<LI><A HREF="#logmsg(debug, message)">logmsg(debug, message)</A></LI>
	</UL>

	<LI><A HREF="#example applications">EXAMPLE APPLICATIONS</A></LI>
	<LI><A HREF="#acknowledgements">ACKNOWLEDGEMENTS</A></LI>
	<LI><A HREF="#known issues">KNOWN ISSUES</A></LI>
	<LI><A HREF="#see also">SEE ALSO</A></LI>
	<LI><A HREF="#author">AUTHOR</A></LI>
	<LI><A HREF="#license">LICENSE</A></LI>
	<LI><A HREF="#cvs id">CVS ID</A></LI>
	<LI><A HREF="#update history">UPDATE HISTORY</A></LI>
</UL>
<!-- INDEX END -->

<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>Spreadsheet::BasicRead - Methods to easily read data from spreadsheets</P>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>Provides methods for simple reading of a Excel spreadsheet row
at a time returning the row as an array of column values.
Properties can be set so that blank rows are skipped.  The heading
row can also be set so that reading always starts at this row which
is the first row of the sheet by default.
Properties can also be set to skip the heading row.</P>
<PRE>
 Note 1. Leading and trailing white space is removed from cell values.</PRE>
<PRE>
 Note 2. Row and column references are zero (0) indexed. That is cell
         A1 is row 0, column 0</PRE>
<P>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
 use Spreadsheet::BasicRead;</PRE>
<PRE>
 my $xlsFileName = 'Test.xls';</PRE>
<PRE>
 my $ss = new Spreadsheet::BasicRead($xlsFileName) ||
    die &quot;Could not open '$xlsFileName': $!&quot;;</PRE>
<PRE>
 # Print the row number and data for each row of the
 # spreadsheet to stdout using '|' as a separator
 my $row = 0;
 while (my $data = $ss-&gt;getNextRow())
 {
    $row++;
    print join('|', $row, @$data), &quot;\n&quot;;
 }</PRE>
<PRE>
 # Print the number of sheets
 print &quot;There are &quot;, $ss-&gt;numSheets(), &quot; in the spreadsheet\n&quot;;</PRE>
<PRE>
 # Set the heading row to 4
 $ss-&gt;setHeadingRow(4);</PRE>
<PRE>
 # Skip the first data line, it's assumed to be a heading
 $ss-&gt;skipHeadings(1);</PRE>
<PRE>
 # Print the name of the current sheet
 print &quot;Sheet name is &quot;, $ss-&gt;currentSheetName(), &quot;\n&quot;;</PRE>
<PRE>
 # Reset back to the first row of the sheet
 $ss-&gt;getFirstRow();</PRE>
<P>
<HR>
<H1><A NAME="required modules">REQUIRED MODULES</A></H1>
<P>The following modules are required:</P>
<PRE>
 Spreadsheet::ParseExcel</PRE>
<P>Optional module File::Log can be used to allow simple logging of errors.</P>
<P>
<HR>
<H1><A NAME="methods">METHODS</A></H1>
<P>There are no class methods, the object methods are described below.
Private class method start with the underscore character '_' and
should be treated as <EM>Private</EM>.</P>
<P>
<H2><A NAME="new">new</A></H2>
<P>Called to create a new BasicReadNamedCol object.  The arguments can
be either a single string (see <A HREF="#synopsis">'SYNOPSIS'</A>)
which is taken as the filename of the spreadsheet of as named arguments.</P>
<PRE>
 eg.  my $ss = Spreadsheet::BasicReadNamedCol-&gt;new(
                  fileName      =&gt; 'MyExcelSpreadSheet.xls',
                  skipHeadings  =&gt; 1,
                  skipBlankRows =&gt; 1,
                  log           =&gt; $log,
                  oldCell       =&gt; 1,
              );</PRE>
<P>The following named arguments are available:</P>
<DL>
<DT><STRONG><A NAME="item_skipHeadings">skipHeadings</A></STRONG><BR>
<DD>
Don't output the headings line in the first call to
<A HREF="#getnextrow">'getNextRow'</A> if true.  This is the first row of the
spreadsheet unless the setHeadingRow function has been called to set
the heading row.
<P></P>
<DT><STRONG><A NAME="item_skipBlankRows">skipBlankRows</A></STRONG><BR>
<DD>
Skip blank lines in the spreadsheet if true.
<P></P>
<DT><STRONG><A NAME="item_log">log</A></STRONG><BR>
<DD>
Use the File::Log object to log exceptions.
If not provided error conditions are logged to STDERR
<P></P>
<DT><STRONG><A NAME="item_fileName">fileName</A></STRONG><BR>
<DD>
The name (and optionally path) of the spreadsheet file to process.
<P></P>
<DT><STRONG><A NAME="item_oldCell">oldCell</A></STRONG><BR>
<DD>
Empty cells returned undef pre version 1.5.  They now return ''.
<P>The old functionality can be turned on by setting argument <EM>oldCell</EM> to true</P>
<P></P></DL>
<P><STRONG>Note that new will die if the spreadsheet can not be successfully opened.</STRONG>
As such you may wish to wrap the call to new in a eval block. See <A HREF="#example applications">xlsgrep</A>
for an example of when this might be desirable.</P>
<P>
<H2><A NAME="getnextrow()"><CODE>getNextRow()</CODE></A></H2>
<P>Get the next row of data from the spreadsheet.  The data is
returned as an array reference.</P>
<PRE>
 eg.  $rowDataArrayRef = $ss-&gt;getNextRow();</PRE>
<P>
<H2><A NAME="numsheets()"><CODE>numSheets()</CODE></A></H2>
<P>Returns the number of sheets in the spreadsheet</P>
<P>
<H2><A NAME="openspreadsheet(filename)"><CODE>openSpreadsheet(fileName)</CODE></A></H2>
<P>Open a new spreadsheet file and set the current sheet to the first
sheet.  The name and optionally path of the
spreadsheet file is a required argument to this method.</P>
<P>
<H2><A NAME="currentsheetnum()"><CODE>currentSheetNum()</CODE></A></H2>
<P>Returns the current sheet number or undef if there is no current sheet.
<A HREF="#setcurrentsheetnum">'setCurrentSheetNum'</A> can be called to set the
current sheet.</P>
<P>
<H2><A NAME="currentsheetname()"><CODE>currentSheetName()</CODE></A></H2>
<P>Return the name of the current sheet or undef if the current sheet is
not defined.  see <A HREF="#setcurrentsheetnum">'setCurrentSheetNum'</A>.</P>
<P>
<H2><A NAME="setcurrentsheetnum(num)"><CODE>setCurrentSheetNum(num)</CODE></A></H2>
<P>Sets the current sheet to the integer value 'num' passed as the required
argument to this method.  Note that this should not be bigger than
the value returned by <A HREF="#numsheets">'numSheets'</A>.</P>
<P>
<H2><A NAME="getnextsheet()"><CODE>getNextSheet()</CODE></A></H2>
<P>Returns the next sheet ``ssBook'' object or undef if there are no more sheets
to process.  If there is no current sheet defined the first sheet
is returned.</P>
<P>
<H2><A NAME="getfirstsheet()"><CODE>getFirstSheet()</CODE></A></H2>
<P>Returns the first sheet ``ssBook'' object.</P>
<P>
<H2><A NAME="cellvalue(row, col)">cellValue(row, col)</A></H2>
<P>Returns the value of the cell defined by (row, col)in the current sheet.</P>
<P>
<H2><A NAME="getfirstrow()"><CODE>getFirstRow()</CODE></A></H2>
<P>Returns the first row of data from the spreadsheet (possibly skipping the
column headings  <A HREF="#new">'skipHeadings'</A> as an array reference.</P>
<P>
<H2><A NAME="setheadingrow(rownumber)"><CODE>setHeadingRow(rowNumber)</CODE></A></H2>
<P>Sets the effective minimum row for the spreadsheet to 'rowNumber', since it
is assumed that the heading is on this row and anything above the heading is
not relavent.</P>
<P><STRONG>Note:</STRONG> the row (and column) numbers are zero indexed.</P>
<P>
<H2><A NAME="setrow(rownumber)"><CODE>setRow(rowNumber)</CODE></A></H2>
<P>Sets the row to be returned by the next call to <A HREF="#getnextrow">'getNextRow'</A>.
Note that if the heading row has been defined and the row number set with setRow
is less than the heading row, data will be returned from the heading row regardless,
unless skip heading row has been set, in which case it will be the row after the
heading row.</P>
<P>
<H2><A NAME="getrownumber()"><CODE>getRowNumber()</CODE></A></H2>
<P>Returns the number of the current row (that has been retrieved).  Note that
row numbers are zero indexed.  If a row has not been retrieved as yet, -1 is
returned.</P>
<P>
<H2><A NAME="logexp(message)"><CODE>logexp(message)</CODE></A></H2>
<P>Logs an exception message (can be a list of strings) using the File::Log
object if it was defined and then calls die message.</P>
<P>
<H2><A NAME="logmsg(debug, message)">logmsg(debug, message)</A></H2>
<P>If a File::Log object was passed as a named argument <A HREF="#new">'new'</A> and
if 'debug' (integer value) is equal to or greater than the current debug
Level (see File::Log) then the message is added to the log file.</P>
<P>If a File::Log object was not passed to new then the message is output to
STDERR.</P>
<P>
<HR>
<H1><A NAME="example applications">EXAMPLE APPLICATIONS</A></H1>
<P>Two sample (but usefull) applications are included with this distribution.</P>
<P>The simplest is dumpSS.pl which will dump the entire contents of a spreadsheet
to STDOUT.  Each sheet is preceeded by the sheet name (enclosed in ***) on
a line, followed by each row of the spreadsheet, with cell values separated by
the pipe '|' character.  There is no special handling provided for cells containing
the pipe character.</P>
<P>A more complete example is xlsgrep.  This application can be used to do a perl
pattern match for cell values within xls files in the current and sub directories.
There are no special grep flags, however this should not be a problem since perl's
pattern matching allows for most requirements within the search pattern.</P>
<PRE>
 Usage is: xlsgrep.pl pattern</PRE>
<P>To do a case insensative search for ``Some value'' in any xls file in the current directory
you would use:</P>
<PRE>
 xlsgrep '(?i)Some value'</PRE>
<P>For further details, see each applications POD.</P>
<P>
<HR>
<H1><A NAME="acknowledgements">ACKNOWLEDGEMENTS</A></H1>
<P>I would like to acknowledge the input and patches recieved from the following:</P>
<P>Ilia Lobsanov, Bryan Maloney, Bill (from Datacraft), nadim and D. Dewey Allen</P>
<P>
<HR>
<H1><A NAME="known issues">KNOWN ISSUES</A></H1>
<P>None, however please contact the author at <A HREF="mailto:gng@cpan.org">gng@cpan.org</A> should you
find any problems and I will endevour to resolve then as soon as
possible.</P>
<P>If you have any enhancement suggestions please send me
an email and I will try to accommodate your suggestion.</P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P>Spreadsheet:ParseExcel on CPAN does all the hard work, thanks
Kawai Takanori (Hippo2000) <A HREF="mailto:kwitknr@cpan.org">kwitknr@cpan.org</A></P>
<P>The included applications dumpSS.pl and xlsgrep.pl</P>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<PRE>
 Greg George, IT Technology Solutions P/L, Australia
 Mobile: +61-404-892-159, Email: gng@cpan.org</PRE>
<P>
<HR>
<H1><A NAME="license">LICENSE</A></H1>
<P>Copyright (c) 1999- Greg George. All rights reserved. This
program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.</P>
<P>
<HR>
<H1><A NAME="cvs id">CVS ID</A></H1>
<P>$Id: BasicRead.pm,v 1.10 2006/04/30 05:35:13 Greg Exp $</P>
<P>
<HR>
<H1><A NAME="update history">UPDATE HISTORY</A></H1>
<PRE>
 $Log: BasicRead.pm,v $
 Revision 1.10  2006/04/30 05:35:13  Greg
 - added getRowNumber()</PRE>
<PRE>
 Revision 1.9  2006/03/05 02:43:34  Greg
 - Update of Acknowledgments</PRE>
<PRE>
 Revision 1.8  2006/03/05 02:31:41  Greg
 - Changes to cellValue return to cater for 'GENERAL' value sometimes returned from OpenOffice spreadsheets
   patch provided by Ilia Lobsanov &lt;samogon@gmail.com&gt;
   see <A HREF="http://www.annocpan.org/~KWITKNR/Spreadsheet-ParseExcel-0.2602/ParseExcel.pm#note_18">http://www.annocpan.org/~KWITKNR/Spreadsheet-ParseExcel-0.2602/ParseExcel.pm#note_18</A></PRE>
<PRE>
 Revision 1.7  2006/01/25 22:17:47  Greg
 - Correction to reading of the first row of the next sheet (without calling getFirstRow).
   Error detected and reported by Tim Rossiter
 - Reviewed memory useage as reported by Ilia Lobsanov - this seems to be in the underlying OLE::Storage_Lite</PRE>
<PRE>
 Revision 1.6  2005/02/21 09:54:08  Greg
 - Update to setCurrentSheetNum() so that the new sheet is handled by BasicRead functions</PRE>
<PRE>
 Revision 1.5  2004/10/08 22:40:27  Greg
 - Changed cellValue to return '' for an empty cell rather than undef (requested by D D Allen).  Old functionality can be maintained by setting named parameter 'oldCell' to true in call to new().
 - Added examples to POD</PRE>
<PRE>
 Revision 1.4  2004/10/01 11:02:21  Greg
 - Updated getNextRow to skip sheets that have nothing on them</PRE>
<PRE>
 Revision 1.3  2004/09/30 12:32:25  Greg
 - Update to currentSheetNum and getNextSheet functions</PRE>
<PRE>
 Revision 1.2  2004/08/21 02:30:29  Greg
 - Added setHeadingRow and setRow
 - Updated documentation
 - Remove irrelavant use lib;</PRE>
<PRE>
 Revision 1.1.1.1  2004/07/31 07:45:02  Greg
 - Initial release to CPAN</PRE>

</BODY>

</HTML>