java - How to save chart from excel as image/PDF? -


i want extract/read chart (bar graph/ pie chart etc.) .xlsx file using apache poi , java , save image or pdf on hard drive.

is possible? if yes, how?

thank you!

after investigation, apparently can see not possible extract charts excel using apache poi , save image or pdf.

the approach 1 can take in situation use com based solution using com4j (http://com4j.kohsuke.org/) convert excel pdf , use apache pdfbox (https://pdfbox.apache.org/) convert pdf image.


giving below brief details how use com4j convert excel pdf programmatically:

  1. generate java classes artifacts excel following command:

    java -jar tlbimp-2.1.jar -o wsh -p com.mycompany.excel4j "c:\program files (x86)\microsoft office\office14\excel.exe"

    we need 3 jars above conversion: com4j-2.1.jar, tlbimp-2.1.jar, args4j-2.0.8.jar

    we may download corresponding jars - http://com4j.kohsuke.org/maven-com4j-plugin/dependencies.html

    for more information, refer: http://com4j.kohsuke.org/

  2. copy generated java artifacts workspace or create jar of these , use after adding application classpath.

  3. use following snippet invoke generated com apis java , convert first sheet of specified excel file pdf (replace accordingly on computer paths mentioned in following snippet excel , pdf files):

    public static void main(string[] args) throws exception {     _application excelapplication = classfactory.createapplication();  _workbook workbook = excelapplication         .workbooks()         .open("c:\\users\\akki\\desktop\\myexcel.xlsx",                 null, null, null, null,                 null, null, null,                 null, null, null, null, null,                 null, null, 0);  workbook.exportasfixedformat(xlfixedformattype.xltypepdf, "c:\\users\\akki\\desktop\\mypdf.pdf", null, null, null, null, null, null, null);  workbook.close(false, null,null, 0);  excelapplication.quit();  system.out.println("converted excel pdf!"); } 

cheers,

akshay


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -