You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Mckeane Thomas <th...@gmail.com> on 2012/07/06 22:08:38 UTC
Reading spreadsheet
Hello,
I want to be able to read a spreadsheet by searching for a column
header and returning the values under that column.
For example if I have a spreadsheet with four column headings:
First Name Last Name DOB Number
john brown 02-05-1988 123
Greg Smith 03-06-1989 456
Gordon Smalls 04-07-1990 789.
I want to be able to read and process the sheet above by reading the
heading example First Name which would return the values associated with
First Name:
First Name:
John
Greg
Gordon
and so forth for each column.
Best regards,
Mckeane
Re: Reading spreadsheet
Posted by Mark Beardsley <ma...@tiscali.co.uk>.
If you know the number of the row that holds the column headings, all you
need to do is something like this;
1. Open the workbook.
2. Get a sheet.
3. Read the row containing the column headings.
4. Iterate through the cells on that row searching for a specific value.
5. Once you find that value, make a note of the cells column index or
number.
6. Get the remaining rows on the sheet one by one.
7. Get the cell whose index matches the cell index of the header cell found
in step number 5 above.
8. Get the value from that cell.
The code you need to perform each of these steps is explained in the various
parts of either the Quick Guide
(http://poi.apache.org/spreadsheet/quick-guide.html) or FAQ
(http://poi.apache.org/faq.html) sections of the webs site. For exaple,
reading a workbook is outlined here -
http://poi.apache.org/spreadsheet/quick-guide.html#ReadWriteWorkbook -
iterating over rows and cells here -
http://poi.apache.org/spreadsheet/quick-guide.html#Iterator - and getting at
a cells contents, here -
http://poi.apache.org/spreadsheet/quick-guide.html#CellContents
Yours
Mark B
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Reading-spreadsheet-tp5710399p5710400.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org