Monday, 17 February 2020 08:49

Convert Excel Chart to Image in Java

Written by  support iceblue
Rate this item
(0 votes)

This article demonstrates how to convert an Excel chart to image using Spire.XLS for Java.

The example Excel file:

Convert Excel Chart to Image in Java

import com.spire.xls.Workbook;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ChartToImage {
    public static void main(String[] args) throws IOException {
        Workbook workbook = new Workbook();
        //Load the Excel file
        workbook.loadFromFile("Chart.xlsx");

        //Save the first chart in the first worksheet as image
        BufferedImage image= workbook.saveChartAsImage(workbook.getWorksheets().get(0), 0);
        ImageIO.write(image,"png", new File("ChartToImage.png"));
    }
}

Output:

Convert Excel Chart to Image in Java

Additional Info

  • tutorial_title: