使用智能标记合并数据时获取通知
Contents
[
Hide
]
Aspose.Cells API 提供工作簿设计器类使用智能标记格式和公式放置在设计师电子表格然后处理工作簿设计器类根据指定的智能标记填充数据。有时,可能需要获取有关单元格引用或正在处理的特定智能标记的通知。这可以通过使用工作簿设计器.CallBack财产和ISmartMarkerCallBack接口随着 Aspose.Cells for Java 8.6.2 的发布而暴露。
使用智能标记合并数据时获取通知
下面的一段代码演示了ISmartMarkerCallBack定义处理回调的新类的接口[工作簿设计器.process](https://reference.aspose.com/cells/java/com.aspose.cells/workbookdesigner#process()) 方法。
This file contains hidden or 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 hidden or 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); |