Smart Markers でデータをマージする際の通知の取得
Contents
[
Hide
]
Aspose.CellsのAPIはWorkbookDesignerクラスを提供しており、スマートマーカーを使用する際に、フォーマットや数式がデザイナースプレッドシートに配置され、WorkbookDesignerクラスによって指定されたスマートマーカーに従ってデータが入力されます。時々、セル参照や特定のスマートマーカーの処理に関する通知が必要になることがあります。これはWorkbookDesigner.CallBackプロパティとリリースAspose.Cells for Java 8.6.2インターフェースとして公開されたISmartMarkerCallBackを使用することで実現できます。
スマートマーカーを使用してデータをマージする際の通知の取得
以下のコードは、ISmartMarkerCallBackインターフェースの使用例を示し、新しいクラスを定義し、WorkbookDesigner.processメソッドのコールバックを処理します。
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 | |
public class SmartMarkerCallBack implements ISmartMarkerCallBack { | |
Workbook workbook; | |
SmartMarkerCallBack(Workbook workbook) { | |
this.workbook = workbook; | |
} | |
@Override | |
public void process(int sheetIndex, int rowIndex, int colIndex, String tableName, String columnName) { | |
System.out.println("Processing Cell : " + workbook.getWorksheets().get(sheetIndex).getName() + "!" | |
+ CellsHelper.cellIndexToName(rowIndex, colIndex)); | |
System.out.println("Processing Marker : " + tableName + "." + columnName); | |
} | |
} |
例をシンプルかつ明確にするために、次のスニペットでは空のデザイナースプレッドシートを作成し、スマートマーカーを挿入し、動的に作成されたデータソースで処理します。
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(GetNotificationsWhileMergingData.class); | |
// Instantiate a new Workbook designer | |
WorkbookDesigner report = new WorkbookDesigner(); | |
// Get the first worksheet of the workbook | |
Worksheet sheet = report.getWorkbook().getWorksheets().get(0); | |
/* | |
* Set the Variable Array marker to a cell. You may also place this Smart Marker into a template file manually using Excel | |
* and then open this file via WorkbookDesigner | |
*/ | |
sheet.getCells().get("A1").putValue("&=$VariableArray"); | |
// Set the data source for the marker(s) | |
report.setDataSource("VariableArray", new String[] { "English", "Arabic", "Hindi", "Urdu", "French" }); | |
// Set the CallBack property | |
report.setCallBack(new SmartMarkerCallBack(report.getWorkbook())); | |
// Process the markers | |
report.process(false); | |
// Save the result | |
report.getWorkbook().save(dataDir); |