セルをXML Map要素にリンク
可能な使用シナリオ
Aspose.Cellsを使用して、セルをXMLマップ要素にリンクできます。この目的のためにはCells.LinkToXmlMap()メソッドを使用してください。
セルをXMLマップ要素にリンクする
次のサンプルコードは、XMLマップを含むソースエクセルファイルを読み込み、セルA1、B2、C3、D4、E5、およびF6をそれぞれXMLマップの要素FIELD1、FIELD2、FIELD4、FIELD5、FIELD7、およびFIELD8にリンクし、その後ブックを出力エクセルファイルに保存します。
出力エクセルファイル(5472517.xlsx)を開き、開発者 > ソースボタンをクリックすると、Microsoft ExcelがセルがXMLマップ要素にリンクされていることを示すと同時に、この画像で表示されているように、それらがハイライト表示されます。
サンプルコード
// 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"); |