Link Cells to XML Map Elements

Possible Usage Scenarios

You can link your cells to XML Map elements using Aspose.Cells for Python via .NET. Please use the Cells.link_to_xml_map() method for this purpose.

The following sample code loads the source excel file which contains XML Map and then links cells A1, B2, C3, D4, E5, and F6 to XML Map elements FIELD1, FIELD2, FIELD4, FIELD5, FIELD7, and FIELD8 respectively and then saves the workbook in output excel file.

If you open the output excel file and click the Developer > Source button, you will see the cells are linked with XML Map elements and they will also be highlighted by Microsoft Excel as shown in this image.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Load sample workbook
wb = Workbook(dataDir + "sample.xlsx")
# Access the Xml Map inside it
map = wb.worksheets.xml_maps[0]
# Access first worksheet
ws = wb.worksheets[0]
# Map FIELD1 and FIELD2 to cell A1 and B2
ws.cells.link_to_xml_map(map.name, 0, 0, "/root/row/FIELD1")
ws.cells.link_to_xml_map(map.name, 1, 1, "/root/row/FIELD2")
# Map FIELD4 and FIELD5 to cell C3 and D4
ws.cells.link_to_xml_map(map.name, 2, 2, "/root/row/FIELD4")
ws.cells.link_to_xml_map(map.name, 3, 3, "/root/row/FIELD5")
# Map FIELD7 and FIELD8 to cell E5 and F6
ws.cells.link_to_xml_map(map.name, 4, 4, "/root/row/FIELD7")
ws.cells.link_to_xml_map(map.name, 5, 5, "/root/row/FIELD8")
# Save the workbook in xlsx format
wb.save(dataDir + "output.xlsx")