Matthew Strawbridge
Matthew Strawbridge

Reputation: 20640

Round-tripping XML -> Excel -> XML

I'd like to use Excel's XML Map feature from server-side C# in a web app. XML maps enable you to associate an XML schema with a workbook and specify which cells map to which parts of the schema. From there you can import XML files to update cell values, and export XML containing the latest values (i.e. if they have been manually changed). You can do this manually on the Developer tab in Excel.

We already have a licence for Aspose Cells, but (despite some recent work in this area) it doesn't seem to fully support XML maps. Has anyone had any success with this?

I've created a test using Excel Interop, which works (i.e. can set up an XML Map programatically and use it to both import and export values). It boils down to this:

XmlMap map = workbook.XmlMaps.Add(xmlSchema, Missing.Value);

// map cell C3 to the question text
var worksheet = (Worksheet)workbook.Worksheets[1];
Range cell = (Range)worksheet.Cells[3, 3];
cell.XPath.Clear(); // just in case
cell.XPath.SetValue(map, "/Root/Question/Text", Missing.Value, false);

// import the XML to populate the mapped cells
map.ImportXml(xmlData, true);

However, that's not really suitable for use on a server because it relies on running the Excel process in the background.

Is it possible to use Microsoft's Open XML SDK to import or export XML via an XML Map? I've found the Map class, but I think that just represents the metadata for a map that already exists. Does the SDK contain this sort of transformation logic or does it just represent a worksheet's content as classes?

Upvotes: 3

Views: 1702

Answers (1)

codewarior
codewarior

Reputation: 441

To further providing you details about XMLMaps feature, currently, Aspose.Cells only supports the following options regarding XML Maps:

  1. It can preserve XmlMaps in the template file and re-save the file with it.
  2. It supports to Import XML Mapping from external sources.
  3. It can remove or check the XML mappings.

Currently it does not support the following at the moment:

  1. It cannot add XML Maps to the Excel file.
  2. It does not export XML Maps to save an external file (We will try to support exporting xml Maps in the second quarter of 2013)

My name is Nayyer and I am developer evangelist at Aspose.

Upvotes: 4

Related Questions