java - Apache POI set Excel chart title -


i'm creating excel workbook scratch. 1 of sheets contains chart, , want set chart title.

apache poi has setcharttitle method on hssfchart, neither xssfchart nor format-agnostic chart have methods set chart title. since need create .xlsx files problem me.

after poking around in poi code , ooxml specifications managed come code setting title on newly created chart:

    if (chart instanceof xssfchart) {         xssfchart xchart = (xssfchart) chart;         ctchart ctchart = xchart.getctchart();         cttitle title = ctchart.addnewtitle();         cttx tx = title.addnewtx();         cttextbody rich = tx.addnewrich();         rich.addnewbodypr();  // body properties must exist, can empty         cttextparagraph para = rich.addnewp();         ctregulartextrun r = para.addnewr();         r.sett("my chart title");     } 

this seems work - can load resulting file in excel 2013 , chart there correct title.

is there easier way this? gotchas need out when changing chart title in workbook created in excel?


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -