ワークシートにアイコンを追加する
Contents
[
Hide
]
Aspose.Cells でワークシートにアイコンを追加
Excel ファイルに ‘アイコン’ を追加する必要がある場合は、このドキュメントが役立ちます。Aspose.Cells を使用して、Excel ファイルにアイコンを追加する方法について説明します。
挿入アイコン操作に対応する Excel インターフェースは次のとおりです。
- ワークシートに挿入するアイコンの位置を選択します
- 挿入->アイコン を左クリックします
- 開いたウィンドウで、上図の赤い四角内のアイコンを選択します
- 挿入 を左クリックすると、Excel ファイルに挿入されます
効果は以下のようになります。
ここでは、Aspose.Cells を使用してアイコンを挿入するための サンプルコード を用意しています。必要なサンプルファイルとアイコンリソースファイルもあります。 Excel インターフェースを使用して、サンプルファイル内のリソースファイルと同じ表示効果のアイコンを挿入しました。
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
プロジェクトで上記のコードを実行すると、次の結果が得られます。