title: Import xml using XML-mapping in OpenXML
body: <p>I've been trying to import XML-data to Excel using an xml-mapping in OpenXML SDK.</p>
  
  <p>I have found multiple examples of doing this using Excel Interop, but not using the SDK. As a side note, I have this working for Word-files, but the procedure is not the same in Excel (CustomXmlPart in Word, CustomXmlMappingPart in Excel).</p>
  
  <p>Maybe it's just not possible using the SDK directly. A workaround might be using named ranges, but I find that less practical.</p>
  
  <p>Edit:
  The scenario is using an Excel-file with an XML-mapping (created as per described <a href="https://support.office.com/en-us/article/Import-XML-data-6eca3906-d6c9-4f0d-b911-c736da817fa4?ui=en-US&amp;rs=en-US&amp;ad=US" rel="nofollow noreferrer">https://support.office.com/en-us/article/Import-XML-data-6eca3906-d6c9-4f0d-b911-c736da817fa4?ui=en-US&amp;rs=en-US&amp;ad=US</a>) as a "template" to fill with data. The could be Customer name, current date or likewise.</p>
  
  <p>I have tried something similar to this. In contrast to Word, the mapping is shown in a CustomXmlMappingsPart. </p>
  
  <pre><code>using (var fileStream = File.Open(@"c:\temp\test.xslx", FileMode.Open))
  {
     SpreadsheetDocument excelDoc = SpreadsheetDocument.Open(fileStream, true);
     // Only one mapping
     // When doing this for word, there is a document.MainDocumentPart.CustomXmlParts
     var mapping = excelDoc.WorkbookPart.GetPartsOfType&lt;CustomXmlMappingsPart&gt;().FirstOrDefault();
     XNamespace mappingNS = "http://demoimport.org/xmlimport";
     var xmlData = new XElement(mappingNS + "ImportRoot",
                                new XElement(mappingNS + "Customer", "Test Customer Name"));
  
     XmlReader reader = xmlData.CreateReader();
     reader.MoveToContent();
  
     using (MemoryStream ms = new MemoryStream())
     {
        xmlData.Save(ms);
        ms.Position = 0;
        // Corrupts the file
        // Probably due to CustomXmlMappingsPart
        mapping.FeedData(ms);
     }   
  }
  </code></pre>