title: Excel XML Newline in Cell
body: <p>I am using LINQ to XML to create an <a href="http://msdn.microsoft.com/en-us/library/aa140066%28office.10%29.aspx" rel="nofollow noreferrer">Excel XML</a> file. I want to include newlines within the cells. Excel uses the <code>&amp;#10;</code> literal to represent a new line. If I try to add this using an XText:</p>
  
  <pre><code>XText newlineElement = new XText( "Foo&amp;#10;Bar" );
  </code></pre>
  
  <p>I get:</p>
  
  <p><code>Foo&amp;amp;#10;Bar</code></p>
  
  <p>Which shows up in Excel as:</p>
  
  <p><code>Foo&amp;#10;Bar</code></p>
  
  <p>Is there a way to write <code>&amp;#10</code> to the XML file without doing a </p>
  
  <pre><code>String.Replace( "&amp;amp;#10;", "&amp;#10;" )
  </code></pre>
  
  <p>over the resulting file text?</p>
  
  <p><strong>EDIT</strong> Here is a code snippet showing how I create a row for the Excel document. I was avoiding it since it is a little messy. :) Let me know if more code would help, or if this just adds more confusion.</p>
  
  <p>In this example, the <code>newlineElement</code> described above is represented by the only XText in the code sample.</p>
  
  <pre><code>const string CELL = "{urn:schemas-microsoft-com:office:spreadsheet}Cell";
  const string DATA = "{urn:schemas-microsoft-com:office:spreadsheet}Data";
  const string STYLE = "{urn:schemas-microsoft-com:office:spreadsheet}StyleID";
  const string TYPE= "{urn:schemas-microsoft-com:office:spreadsheet}Type";   
  const string HEIGHT = "{urn:schemas-microsoft-com:office:spreadsheet}Height";
  const string ROW = "{urn:schemas-microsoft-com:office:spreadsheet}Row";
  </code></pre>
  
  <p>...</p>
  
  <pre><code>XElement rowElement = new XElement( Row,
                                      new XElement( CELL,
                                          new XAttribute( STYLE, "s0" ) ),
                                      new XElement( CELL,
                                          new XElement( DATA,
                                              new XText( description.Replace("\n", "&amp;#10;") ), 
                                              new XAttribute( TYPE, "String" ) ),
                                          new XAttribute( STYLE, "sWrap" ) ),
                                      new XElement( CELL,
                                          new XAttribute( STYLE, "s0" ) ),
                                      new XAttribute( HEIGHT, height ) );
  </code></pre>
  
  <p>This produces:</p>
  
  <pre><code>  &lt;ss:Row ss:Height="45"&gt;
      &lt;ss:Cell ss:StyleID="s0" /&gt;
      &lt;ss:Cell ss:StyleID="sWrap"&gt;
        &lt;ss:Data ss:Type="String"&gt;Foo&amp;amp;#10;Bar&lt;/ss:Data&gt;
      &lt;/ss:Cell&gt;
      &lt;ss:Cell ss:StyleID="s0" /&gt;
    &lt;/ss:Row&gt;
  </code></pre>
  
  <p>Thanks for the help thus far!</p>