スマート マーカーを使用してデータを結合する際の通知の取得
Contents
[
Hide
]
Aspose.Cells API は、WorkbookDesignerクラスへスマート マーカーの操作フォーマットと数式が配置されている場所デザイナー スプレッドシートで処理し、WorkbookDesignerクラスを使用して、指定されたスマート マーカーに従ってデータを入力します。場合によっては、セル参照または処理中の特定のスマート マーカーに関する通知を取得する必要がある場合があります。これは、WorkbookDesigner.CallBackプロパティとISmartMarkerCallBackAspose.Cells for Java 8.6.2 のリリースで公開されたインターフェース。
スマート マーカーを使用してデータをマージする際に通知を受け取る
次のコードは、ISmartMarkerCallBackコールバックを処理する新しいクラスを定義するインターフェース[WorkbookDesigner.process](https://reference.aspose.com/cells/java/com.aspose.cells/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); |