Well to my mind you have roughly three options as I am not at all certain
there is an easy, in-built way to accomplish this task; you will need to do
some additional coding IMO.

The first option would be to test out the MissingCellPolicy technique that
Nick suggested in his earlier reply to your question.

Secondly, I would process the rows twice. The first pass would be undertaken
simply to establish the length of the longest row - and to establish the
maximum number of cells on a row therefore. Next, I would use this
nformation to initialise each List so that it contained the correct amount
of padding to ensure the matrix was 'square'. The second pass would actually
populate the Lists with the 'real' data, replacing the placeholders where
necessary.

Finally, you could prcess each row and accept that the resulting lists would
hold different numbers of cells. At the same time as processing the rows,
you would keep track of what the largest number of cells on a row is and use
this value when reading the contents of the List. If there were fewer cells
in the List then simply return the relevant number of 'padding' cells to
satisfy the requirements of your business rules.

Yours

Mark B


Tyagi wrote:
> 
> Hi Nick,
> 
> Thanks for solution.  
> I read the data from excel file and convert it to List(it represent Sheet
> of excel file) of List(it represent one row). My business logic assume
> that all the List(represent Rows) would have same number of elements. 
> 
> I have a Sheet in excel which contain no of rows and each row have
> different number of column. I read the data from file successfully and
> convert it to List(represent rows) but some list have two elements and
> some have three due to which ArrayIndexOutOfBound exception thrown by
> business logic.
> 
> So I need that appache poi read the data from excel file and return same
> number of cells for each row.
> Please suggest. Is there Any Way?
> 
> I have checked out all the methods provided by HSSFWorkbook, but
> unfortunatly it is not helpful for me. 
> Thanks In Advance.
> 
> 
> Nick Burch-11 wrote:
>> 
>> On Wed, 17 Mar 2010, Tyagi wrote:
>>> Is there any way through which I get 5 cells for each row ?
>> 
>> http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html#setMissingCellPolicy(org.apache.poi.ss.usermodel.Row.MissingCellPolicy)
>> 
>> Nick
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Read-data-from-excel-file-in-matrix.-tp27929789p27950913.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to