セルをXML Map要素にリンク
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsを使用して、セルをXMLマップの要素にリンクできます。この目的にはCells.LinkToXmlMap()メソッドを使用してください。
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によって強調表示されます。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Load sample workbook | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access the Xml Map inside it | |
XmlMap map = wb.Worksheets.XmlMaps[0]; | |
// Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
// Map FIELD1 and FIELD2 to cell A1 and B2 | |
ws.Cells.LinkToXmlMap(map.Name, 0, 0, "/root/row/FIELD1"); | |
ws.Cells.LinkToXmlMap(map.Name, 1, 1, "/root/row/FIELD2"); | |
// Map FIELD4 and FIELD5 to cell C3 and D4 | |
ws.Cells.LinkToXmlMap(map.Name, 2, 2, "/root/row/FIELD4"); | |
ws.Cells.LinkToXmlMap(map.Name, 3, 3, "/root/row/FIELD5"); | |
// Map FIELD7 and FIELD8 to cell E5 and F6 | |
ws.Cells.LinkToXmlMap(map.Name, 4, 4, "/root/row/FIELD7"); | |
ws.Cells.LinkToXmlMap(map.Name, 5, 5, "/root/row/FIELD8"); | |
// Save the workbook in xlsx format | |
wb.Save(dataDir + "output.xlsx"); |