将 Cells 链接到 XML 映射元素
Contents
[
Hide
]
可能的使用场景
您可以使用 Aspose.Cells 将您的单元格链接到 XML 地图元素。请使用Cells.LinkToXmlMap()为此目的的方法。
将 Cells 链接到 Xml 映射元素
下面的示例代码加载源文件其中包含 XML 映射,然后将单元格 A1、B2、C3、D4、E5 和 F6 分别链接到 XML 映射元素 FIELD1、FIELD2、FIELD4、FIELD5、FIELD7 和 FIELD8,然后将工作簿保存在输出excel文件.
如果你打开输出excel文件然后单击 Developer > Source 按钮,您将看到单元格与 XML Map 元素链接,它们也将由 Microsoft Excel 突出显示,如此图所示。
This file contains hidden or 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"); |