Lien Cells vers les éléments de carte XML
Contents
[
Hide
]
Scénarios d’utilisation possibles
Vous pouvez lier vos cellules aux éléments XML Map en utilisant Aspose.Cells. Veuillez utiliser leCells.LinkToXmlMap() méthode à cet effet.
Lien Cells vers les éléments de carte XML
L’exemple de code suivant charge lefichier excel source qui contient XML Map, puis relie les cellules A1, B2, C3, D4, E5 et F6 aux éléments XML Map FIELD1, FIELD2, FIELD4, FIELD5, FIELD7 et FIELD8 respectivement, puis enregistre le classeur dansfichier excel de sortie.
Si vous ouvrez lefichier excel de sortie et cliquez sur leDéveloppeur > Source, vous verrez que les cellules sont liées avec des éléments XML Map et elles seront également mises en évidence par Microsoft Excel comme indiqué dans cette image.
Exemple de code
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.getSharedDataDir(LinkCellstoXmlMapElements.class) + "articles/"; | |
// Load sample workbook | |
Workbook wb = new Workbook(dataDir + "LinkCellstoXmlMapElements_in.xlsx"); | |
// Access the Xml Map inside it | |
XmlMap map = wb.getWorksheets().getXmlMaps().get(0); | |
// Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Map FIELD1 and FIELD2 to cell A1 and B2 | |
ws.getCells().linkToXmlMap(map.getName(), 0, 0, "/root/row/FIELD1"); | |
ws.getCells().linkToXmlMap(map.getName(), 1, 1, "/root/row/FIELD2"); | |
// Map FIELD4 and FIELD5 to cell C3 and D4 | |
ws.getCells().linkToXmlMap(map.getName(), 2, 2, "/root/row/FIELD4"); | |
ws.getCells().linkToXmlMap(map.getName(), 3, 3, "/root/row/FIELD5"); | |
// Map FIELD7 and FIELD8 to cell E5 and F6 | |
ws.getCells().linkToXmlMap(map.getName(), 4, 4, "/root/row/FIELD7"); | |
ws.getCells().linkToXmlMap(map.getName(), 5, 5, "/root/row/FIELD8"); | |
// Save the workbook in xlsx format | |
wb.save(dataDir + "LinkCellstoXmlMapElements_out.xlsx"); |