XLS charts to JPG conversion

Hello Team,
We are trying to convert some charts from xls file to JPG images, but we are facing below issues,

  1. In case of 2D charts output images has black background.
  2. Also chart data like X-axis data is missing in image.
  3. In case of pie-charts, data from side bar after M13 is missing.

Please find attached input and output samples files and code snippet.
could you please help on this?

       String dir = "/Users/mb/Documents/mb/el/conversionfiles/";
        Workbook book = new Workbook(dir + "sample.xls");

        for (int i = 0; i < book.getWorksheets().getCount(); i++) {

            for (int j = 0; j < book.getWorksheets().get(i).getCharts().getCount(); j++) {


                Chart chart = book.getWorksheets().get(i).getCharts().get(j);
                chart.toImage(dir + "WToImage-out" + i + "_" + j + ".jpg");
            }

        }

conversionfiles.7z (1.6 MB)

@m.bansode,

Thanks for the template files.

Please notice, I am able to reproduce the issue as you mentioned by converting the charts in the template files to JPG image files. I confirmed the following problems:

  1. In case of 2D charts output images has black background.—> Found the issue but this issue can be corrected by using some vector image format like PNG.
  2. Also chart data like X-axis data is missing in image.----> Found the issue.
  3. In case of pie-charts, data from side bar after M13 is missing.—> Found there are many (unnecessary) legend entries missing.

I have logged a ticket with an id “CELLSJAVA-44904” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

@Amjad_Sahi, thanks for quick response on this.

Please see my reply below,

  1. In case of 2D charts output images has black background.—> Found the issue but this issue can be corrected by using some vector image format like PNG.
    m.bansode: We even tried PNG format but X-axis and other chart data is missing after conversion.

  2. In case of pie-charts, data from side bar after M13 is missing.—> Found there are many (unnecessary) legend entries missing.
    m.bansode: Could you please elaborate I didn’t understand it completely?

@m.bansode,

Yes, using PNG can only fix black background issue.

There are some legend entries without item names. Anyways, we will fix the issue and hopefully image for the chart would be rendered same as what MS Excel shows.

Hi @m.bansode
For issue 2, please Note that the text “G1…G5” in the file belongs to another "shape ", not in that “Chart”, so when you only convert that “Chart” to image, they will not contain in it.
If you turn the entire file into a PDF, you can see them.
220929.png (21.0 KB)

@Amjad_Sahi, just want to know do you guys provide any ETA for fix as we have Aspose license.

@m.bansode,

Please spare us little time to evaluate your issue in details, so we could provide an ETA (if possible) in the next few days on it.

1 Like

@m.bansode,

  1. The JPG format has no transparent background, We will set the default JPG background to white. This will take effect in upcoming v22.10.
  2. This is not a problem with the APIs as we we already explained to you.
  3. We are working on it.

Hi @m.bansode
For issue 3, We optimized it and generated the following image, which will also be available in version 22.10.
Chart1[0].Shape[0].Java.New.Png (34.4 KB)

Thanks @leoluo

Thanks @Amjad_Sahi

@m.bansode,

You are welcome.

@m.bansode,

This is to inform you that your issues are resolved now. The fix will be included in the next upcoming release/update (Aspose.Cells for Java v22.10) which is scheduled in the next couple of days. You will also be notified when the next version is released.

1 Like

The issues you have found earlier (filed as CELLSJAVA-44904) have been fixed in this update. This message was posted using Bugs notification tool by Peyton.Xu