aspose file tools*
The moose likes Other Open Source Projects and the fly likes Apache POI column Iternator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Apache POI column Iternator" Watch "Apache POI column Iternator" New topic
Author

Apache POI column Iternator

sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 271
Hi,

I have method to read XLS as below

I have attached sample XLS.

I need to convert that XLS file to XML file as attached using apache POI and java program.

I need to iterate the XLS file based on first column to do all this. If first column is null ignore. Instead it has values like

AAA9115
AAA9116
AAA911
AAA9119
AAA9118



BBB911
BBB912
BBB913
BBB914
BBB919
BBB9117
BBB9114
BBB9113



then read that row and then to convert it to XML.
each tag _1, _2, _3,_4,_5,_6 gets values from corresponding XLS cells.

I looked for column iterator similar to row iterator to check if it is null or not
//Iterator colIter = mySheet.colIterator();
but API does not have it. How Can I achieve this task.

Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance



[Thumbnail for xls1.JPG]


[Thumbnail for xml1.JPG]

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42294
    
  64
Why do you need a column iterator? It's easy to get at any individual cell via HSSFSheet.getRow(...).getCell(...).

By the way, I advise to use the classes in the org.apache.poi.ss package instead of the ones in org.apache.poi.hssf. That way, you can process XSLX files in addition to XLS files.


Ping & DNS - my free Android networking tools app
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 271
Sure.

How to check on a row and see if the first column of that partical row is not null right

can i modify below line
>> while(rowIter.hasNext()){
to something as shown below(i am not sure exactly how to check)
>> while(rowIter.hasNext()& not null){

please advise
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 271
I was thinking like

>>if (cell.getStringCellValue() != null && !cell.getStringCellValue().lenght==0)


but not sure how to check it for first cell(column) of each row.

Please advise
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 271
I kind of wrote like above that is printing all the values in a row even if the first one is still null .

Instead i
want to get all the values in a row if the first one isn't null

Please advise

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42294
    
  64
The code does seem to check for "if (myRow.getCell(0) != null){" - if that's not the correct implementation of "if the first one isn't null", then how do you define it?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Apache POI column Iternator