将图标添加到工作表

在 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);

当你在你的项目中执行上面的代码时,你会得到如下结果: