By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

Carriage returns in XML Excel sheet created using XmlDocument and XmlTextWriter

P: n/a
st
Hi,

I've a routine that exports a DB query to Excel by building an
XmlDocument and saving to a XmlTextWriter. I'm having trouble with
carriage returns in a mailing address not showing up in the final Excel
sheet.

What's added to the InnerText of an XmlDocument is something similar
to:

"Name \r\nAddress1\r\nAddress2 \r\nAddress3 \r\nAddress4\r\n"

After going through the XmlTextWriter the resulting XML is:

</Data></Cell><Cell ss:StyleID="s26"><Data ss:Type="String">
Name
Address1
Address2
Address3
Address4

And what appears in the address cell of the Excel sheet is:
Name Address1 Address 2 Address 3 Address 4

I posted a similar topic yesterday and spent much of today working on
the issue without success, trying out various combinations of:
space = "preserve" in the XML
XmlDocument.PreserveWhitespace = true
XmlTextWriter.WriteAttributeString("xml", "space", null, "preserve");

Can anyone assist?

Many thanks,

Simon Lane

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

An ugly solution, but it's a problem of Excel I think - try replacing in
your xml Environment.NewLine with "\n" or VbLf for C# and VB.NET
respectively.

Hope This Helps
Martin Dechev
<st@jpa.co.jp> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I've a routine that exports a DB query to Excel by building an
XmlDocument and saving to a XmlTextWriter. I'm having trouble with
carriage returns in a mailing address not showing up in the final Excel
sheet.

What's added to the InnerText of an XmlDocument is something similar
to:

"Name \r\nAddress1\r\nAddress2 \r\nAddress3 \r\nAddress4\r\n"

After going through the XmlTextWriter the resulting XML is:

</Data></Cell><Cell ss:StyleID="s26"><Data ss:Type="String">
Name
Address1
Address2
Address3
Address4

And what appears in the address cell of the Excel sheet is:
Name Address1 Address 2 Address 3 Address 4

I posted a similar topic yesterday and spent much of today working on
the issue without success, trying out various combinations of:
space = "preserve" in the XML
XmlDocument.PreserveWhitespace = true
XmlTextWriter.WriteAttributeString("xml", "space", null, "preserve");

Can anyone assist?

Many thanks,

Simon Lane

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.