向工作表添加图标

在Aspose.Cells中向工作表添加图标

如果您需要使用Aspose.Cells在Excel文件中添加’图标',那么本文档可以为您提供一些帮助。

对应于插入图标操作的Excel界面如下:

  • 选择要插入到工作表中的图标的位置
  • 左键单击插入->图标
  • 在打开的窗口中,选择上图中红色矩形所示的图标
  • 单击 插入,将其插入到 Excel 文件中。

效果如下:

这里,我们已经准备了样本代码,以帮助您使用Aspose.Cells插入图标。还有一个必要的样本文件和一个图标资源文件。我们使用Excel界面在样本文件中插入一个与资源文件相同的显示效果的图标。

Java

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Read icon resource file data
String fileName = "icon.svg";
FileInputStream fsSource = new FileInputStream(fileName);
byte[] bytes = fsSource.readAllBytes();
fsSource.close();
// Create workbook from sample file
Workbook workbook = new Workbook("sample.xlsx");
// Access first worksheet from the collection
Worksheet sheet = workbook.getWorksheets().get(0);
// Add the icon to the worksheet
sheet.getShapes().addIcons(3, 0, 7, 0, 100, 100, bytes, null);
//Set a prompt message
Cell c = sheet.getCells().get(8, 7);
c.putValue("Insert via Aspose.Cells");
Style s = c.getStyle();
s.getFont().setColor(Color.getBlue());
c.setStyle(s);
//Save.You can check your icon in this way.
workbook.save("sample2.xlsx", SaveFormat.XLSX);

当您在项目中执行上述代码时,将获得以下结果: