リンクされた形状の値をリフレッシュ
Contents
[
Hide
]
Excelファイルには、あるセルにリンクされたリンクされた図形がある場合があります。Microsoft Excelでは、リンクされたセルの値を変更すると、リンクされた図形の値も変更されます。これはAspose.Cellsでも同様に機能し、XLSまたはXLSX形式でブックを保存する場合にうまく機能します。ただし、ブックをPDFまたはHTML形式で保存する場合は、リンクされた図形の値を更新するためにWorksheet.getShapes().updateSelectedValue()メソッドを呼び出す必要があります。
例
次のスクリーンショットは、以下に示すサンプルコードで使用されるソースExcelファイルを示しています。Picture 1 がセルA1にリンクされています。セルA1の値をAspose.Cellsで変更し、Picture 1の値を更新し、PDF形式で保存します。
指定されたリンクからsource Excel fileとoutput PDFをダウンロードできます。
リンクされた図形の値を更新する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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RefreshValuesOfLinkedShapes.class); | |
// Create workbook from source file | |
Workbook workbook = new Workbook(dataDir + "LinkedShape.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Change the value of cell A1 | |
Cell cell = worksheet.getCells().get("A1"); | |
cell.putValue(100); | |
// Update the value of the Linked Picture which is linked to cell A1 | |
worksheet.getShapes().updateSelectedValue(); | |
// Save the workbook in pdf format | |
workbook.save(dataDir + "output.pdf", SaveFormat.PDF); |