在使用智能标记合并数据时获取通知
Contents
[
Hide
]
Aspose.Cells API 提供 WorkbookDesigner 类来处理智能标记,其中格式设置和公式放置在设计电子表格中,然后使用WorkbookDesigner 类根据指定的智能标记填充数据。有时,可能需要获取有关正在处理的单元格引用或特定智能标记的通知。通过使用WorkbookDesigner.CallBack 属性和ISmartMarkerCallBack 接口,可以在 Aspose.Cells for Java 8.6.2 版本中实现。
在使用智能标记合并数据时获取通知
以下代码片段演示了如何使用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); |