Hi All,

I have an excel file containg chart.I am able to read the chart from excel file using POI XSSF.
But I am not able to save the XSSFChart as an image.I want the chart to be stored in my harddrive as an image(.jpg or .png).Please find my code fragment below.

    FileInputStream file = new FileInputStream(new File("C:\\chart.xlsx"));
    XSSFWorkbook workbook = new XSSFWorkbook (file);
    XSSFSheet sheet = workbook.getSheetAt(0);
    XSSFDrawing drawing = sheet.createDrawingPatriarch();
    List<XSSFChart> listChart=drawing.getCharts();
    System.out.println(listChart.size());

Please help.

Hi All,

Could you please provide any suggestion on the above topic.My only criteria is to save an excel chart as an image in my hardrive as JPEG or PNG format.

public static void saveToFile(BufferedImage img)
    throws FileNotFoundException, IOException
    {

        File outputfile = new File("D:\\Sample.png");
    ImageIO.write(img, "png", outputfile);
    }

Is this what you are looking for?
I assume you are using windows os for the path

@Slavi not exactly, question is how to get XSSFDrawing or XSSFPicture to some stream format that can be used to create image.

You should spent little more time reading question and have look on code, API before calling generic search for Java code ;)

I seriously doubt whether what he wants is going to work at all. He seems under the impression that XSSFPicture will magically turn the spreadsheet into a screenshot of what it would look like when displayed in something like Excel, which of course is not true at all.

Hi peter_budo,

First of all,Thanks for your reply.Yeah,you are right.I want XSSFPicture to some stream format that can be used to create image.But I got stuck to this.
The 5 th line fo my code(List<XSSFChart> listChart=drawing.getCharts();) is getting all the charts from the page.I need those charts as an image.The manual process is to copy the chart ,paste it in any image editor and then save the an image in JPEG or other format.Then I am going to prepare a report based on that image.Dynamic report preparation is alrady done.But,I don't want any manual intervention as I said earlier.I want those chart to be saved as an image in my HD via code.But,I am unable to do it.Is there any way you can suggest me?It is going to be a big help for me.Thanks in Advance.

Sorry I never did this with POI.Given that so far nobody provided usable answer you may want to try their mailing list and ask directly contributors http://poi.apache.org/mailinglists.html

Hi peter_budo,

Thanks for the reply.

Hi subhra,
Did you get solution to the problem stated above? I am also having same requirement as that of yours.

Thanks~

XSSFChart given dataseries and input stream but this input stream not generated image file . only given chart xml file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.