Härma notifikationer vid sammanfogning av data med Smart Markers
Contents
[
Hide
]
Aspose.Cells API:erna erbjuder WorkbookDesigner klassen för att arbeta med Smart Markers, där formatering & formler placeras i designer spreadsheets och sedan bearbetas med WorkbookDesigner klassen för att fylla data enligt angivna Smart Markers. Ibland kan det vara nödvändigt att få notifieringar om cellreferensen eller en specifik Smart Marker som bearbetas. Detta kan uppnås med egenskapen WorkbookDesigner.CallBack och gränssnittet ISmartMarkerCallBack som exponeras med version 8.6.2 av Aspose.Cells for Java.
Få notifieringar vid sammanslagning av data med Smart Markers
Följande kodexempel visar användningen av gränssnittet ISmartMarkerCallBack för att definiera en ny klass som hanterar callback för WorkbookDesigner.process metoden.
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); | |
} | |
} |
För att hålla exemplet enkelt och koncis, skapar följande kodsnutt en tom designer spreadsheet, infogar en Smart Marker och bearbetar den med den dynamiskt skapade datakällan.
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); |