title: OpenXml, Word and C#
body: <p>Here is my problem: I'm trying to perform a mail merge using <strong>OpenXml</strong> and <strong>C#</strong>. To do this, I have to create a Word document which has the same number of pages as lines in my data set (My data set is a <strong>CSV file</strong>).</p>
  
  <p>I create a new document, and I'm trying to copy my template on each page of this document. Unfortunately, only the first page has the correct format (my template is copied on it). To copy, I use the <code>InnerXml</code> that I'm trying to copy from my template to each page of my new word document.</p>
  
  <p>I know that my problem comes from my instructions, but I don't know how to fix it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>string fileName = @"MyTemplate";
  using (WordprocessingDocument pkgDoc = WordprocessingDocument.Open(fileName, true))
  {
      pkgDoc.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
      var test = (pkgDoc.MainDocumentPart.RootElement.InnerXml);
  
      string filenamecible = @"@MyNewWordDocument";
  
      using (WordprocessingDocument package = WordprocessingDocument.Create(filenamecible, WordprocessingDocumentType.Document))
      {
          MainDocumentPart mainPart = package.AddMainDocumentPart();
  
          //Create DOM tree for simple document. 
  
          mainPart.Document = new Document();
  
          for (int i = 0; i &lt; csvline.Count; i++)
          {
              mainPart.RootElement.InnerXml = test;
              var x = new Break() { Type = BreakValues.Page };;
              mainPart.Document.Append(x);
              mainPart.Document.Save();
          }
  
          package.MainDocumentPart.Document.Save();
      }
  
  }
  </code></pre>