tags:

views:

309

answers:

1

I' trying to get the following string to output to a cell in Excel using the 2003 XML capabilities "Cheese\nBread" and at the moment it ignores the line break.

If I create a file with the desired effect then I get the following output

<Cell ss:StyleID="s62"><Data ss:Type="String">Cheese&#10;Monkey</Data></Cell>

Okay, so I try doing...

text.Replace('\n',(char)10);

or text.Replace("\n"," ");

To no avail, the first does nothing useful and in the second the XmlWriter simply escapes it with an & which is really helpful.

Any ideas, maybe a setting on the .NET XmlWriter?

+1  A: 

Try setting xml:space="preserve" on the Data element:

<Cell ss:StyleID="s62"><Data ss:Type="String" xml:space="preserve">Cheese
Monkey</Data></Cell>
Lucero
hmm on second look this didn't work for me (the words wrapped simply due to the column size which is why I thought it worked)
Chris Meek
In that case your Excel version does not handle XML correctly, and you may have to do postprocessing of the XML text, for instance with a Regex, or by creating your own XmlTextWriter derivate which replaces the newlines with when WriteString is invoked while the writer is on a Data tag.
Lucero
thanks, I'll try that
Chris Meek