This article will introduce how to add a picture to Excel chart in java applications by using Spire.XLS for java.
import com.spire.xls.*; import com.spire.xls.core.IPictureShape; import com.spire.xls.core.IShape; import java.awt.*; public class addPictureToChart { public static void main(String[] args) { //Load the document from disk Workbook workbook = new Workbook(); workbook.loadFromFile("Sample.xlsx"); //get the first worksheet Worksheet sheet = workbook.getWorksheets().get(0); //get the first chart Chart chart = sheet.getCharts().get(0); //add the picture to chart and set its format IShape picture = chart.getShapes().addPicture("48.png"); ((IPictureShape) picture).getLine().setDashStyle(ShapeDashLineStyleType.DashDotDot); ((IPictureShape) picture).getLine().setForeColor(Color.blue); //save the document String result = "output/AddPictureToChart.xlsx"; workbook.saveToFile(result, ExcelVersion.Version2010); } }
Effective screenshot after adding picture to Excel Chart: