• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Apache POI column Iternator

 
Ranch Hand
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
xls1.JPG
[Thumbnail for xls1.JPG]
xls file
xml1.JPG
[Thumbnail for xml1.JPG]
xml file
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sai rama krishna
Ranch Hand
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic