java - How can I change TextBox in Excel with XSSF from Apache POI -


i using apache poi process excel file. excel file has 2 textboxes read text , change it. how possible xssf model? not want create new textbox- know how this. far trying, there no textbox anywhere there (that can see).

xssfworkbook wb = //get workbook somehow         xssfsheet sheet = wb.getsheetat(0);         iterator<row> rowiterator = sheet.rowiterator();         while(rowiterator.hasnext()){             row row = rowiterator.next();             iterator<cell> celliterator = row.celliterator();             while(celliterator.hasnext()){                 cell cell = celliterator.next();             }         }         for(packagepart pp : wb.getallembedds()){          } 

so textboxes?

here's did obtain references textboxes , change contents in poi 3.10.

for xssf (untested):

xssfdrawing draw = sheet.createdrawingpatriarch(); list<xssfshape> shapes = draw.getshapes(); iterator<xssfshape> = shapes.iterator();  while(it.hasnext()) {                xssfshape shape = it.next();     if (shape instanceof xssftextbox){         xssftextbox textbox = (xssftextbox) shape;         textbox.settext("foo"); // take xssfrichtextstring instead     } }  

for hssf:

hssfpatriarch pat = (hssfpatriarch) sheet.createdrawingpatriarch(); list<hssfshape> children = pat.getchildren(); iterator<hssfshape> = children.iterator(); hssfrichtextstring richstr = new hssfrichtextstring("foo");   while(it.hasnext()) {                hssfshape shape = it.next();     if (shape instanceof hssftextbox){         hssftextbox textbox = (hssftextbox) shape;         textbox.setstring(richstr);     } } 

it doesn't seem solution flexible though since setting different values different textboxes require conditional logic. luckily me, merely changing of textboxes same text.

adapted from: obtain textbox value excel in java


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -