java - apache poi - reading comments from blank and missing (null) cells -


i'm trying read comments excel documents cell's (using apache poi). have problem when empty (or missing) cells contains comments.

currently solutions found to:

  • iterate every row last not empty column
  • get (even empty) cells
  • check if cell's comment not empty
  • if true: handle comment

some code:

if (row != null) {   cell = row.getcell(cellnum, row.create_null_as_blank);   cellcomment = cell.getcellcomment();   if (cellcomment != null)     ... } 

main problems can't read comments empty lines , comments after last not empty cell. increasing performance (comparing reading row cells) nice, main point read documents comments.

you can read comments of blank cell or null cell using missingcellpolicy, row.getcell(int cellnum, missingcellpolicy policy) allows deal cells blank or null.

for example in sheet, 7th row blank , 5th col have comment (say "hello"), , need read comment. following:

 comment comment = sheet.getrow(7).getcell(5, row.create_null_as_blank).getcellcomment();   system.out.println(comment.getstring()); 

will print "hello".


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -