java - Copy comments from one excel sheet to another with Apache POI -
i have cell in 1 excel sheet contains comment. created this:
creationhelper factory = wb.getcreationhelper(); drawing drawing = sheet.createdrawingpatriarch(); // when comment box visible, have show in 5x70 space clientanchor anchor = factory.createclientanchor(); anchor.setcol1(cell.getcolumnindex()); anchor.setcol2(cell.getcolumnindex()+5); anchor.setrow1(row.getrownum()); anchor.setrow2(row.getrownum()+70); comment comment = drawing.createcellcomment(anchor); string text = ""; richtextstring str = factory.createrichtextstring(text); comment.setstring(str); row.createcell(0).setcellcomment(comment);
now have new project, want copy comment cell of sheet, should work that:
xssfrow row_master_a = null; xssfrow row_slave_a = null; for(int j = 4;j<anz_neu+4;j++){ row_master_a = sheet_master.getrow(4+anz_neu+3-j); if(row_master_a == null){ row_master_a = sheet_master.createrow(4+anz_neu+3-j); } row_master_a.setheightinpoints(40); row_slave_a = sheet_slave.getrow(j); row_master_a.createcell(0).setcellcomment(row_slave_a.getcell(0).getcellcomment());`
i don't errors, don't have comment in new sheet. can help?
thanks
you have create separate comment object , copy string contents comment-object tied sheet.
i.e. like
drawing drawing_master = sheet_master.createdrawingpatriarch(); comment comment_master = drawing_master.createcellcomment(anchor); comment_master.setstring(row_slave_a.getcell(0).getcellcomment().getstring()); row_master_a.createcell(0).setcellcomment(comment_master);
Comments
Post a Comment