Add Icons to Worksheet

Add Icons to Worksheet in Aspose.Cells for Python via Java

If you need to use Aspose.Cells for Python via Java to add ‘icons’ in an Excel file, then this document can provide you with some help.

Insert in Excel

The Excel interface corresponding to the insert icon operation is as follows:

  • Select the position of the icon to be inserted in the worksheet
  • Left click Insert->Icons
  • In the window that opens, select the icon in the red rectangle in the figure above
  • Left click Insert,it will be inserted into the Excel file.

The effect is as follows:

Here, we have prepared sample code to help you insert icons using Aspose.Cells for Python via Java.There is also a necessary sample file and an icon resource file.We used the Excel interface to insert an icon with the same display effect as the resource file in the sample file.

Insert in Python via Java

import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook, Color, SaveFormat
dirPath = "" #Your test path
with open(dirPath + 'icon.svg', 'rb') as f:
byte_data = f.read()
# Create workbook from sample file
workbook = Workbook(dirPath + "sample.xlsx")
# Access first worksheet from the collection
sheet = workbook.getWorksheets().get(0)
# Add the icon to the worksheet
sheet.getShapes().addIcons(3, 0, 7, 0, 100, 100, byte_data, None);
#Set a prompt message
c = sheet.getCells().get(8,7);
c.setValue("Insert via Aspose.Cells")
s = c.getStyle();
s.getFont().setColor(Color.getBlue())
c.setStyle(s)
#Save.You can check your icon in this way.
workbook.save(dirPath + "sample2.xlsx", SaveFormat.XLSX)
jpype.shutdownJVM()

Execution Results

When you execute the above code in your project, you will get the following results: