セルをXML Map要素にリンク
可能な使用シナリオ
Aspose.Cells for Python via .NETを使用して、XMLマップの要素にセルをリンクさせることができます。この目的のためにCells.link_to_xml_map()メソッドを使用してください。
Xml Map要素にセルをリンク
次のサンプルコードは、XML Mapを含むsource excel fileを読み込み、セルA1、B2、C3、D4、E5、F6をそれぞれXML Map要素FIELD1、FIELD2、FIELD4、FIELD5、FIELD7、FIELD8にリンクし、output excel fileとしてブックを保存します。
output excel fileを開いて、開発者 > ソース ボタンをクリックすると、セルがXMLマップの要素にリンクされ、Microsoft Excelによって強調表示されます。
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") |