Carriage returns in XML Excel sheet created using XmlDocument and XmlTextWriter

Discussion in 'ASP .Net' started by st@jpa.co.jp, Oct 7, 2005.

  1. Guest

    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
    , Oct 7, 2005
    #1
    1. Advertising

  2. 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
    <> wrote in message
    news:...
    > 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
    >
    Martin Dechev, Oct 7, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shoval Tomer
    Replies:
    0
    Views:
    437
    Shoval Tomer
    Jul 9, 2003
  2. Bob
    Replies:
    0
    Views:
    399
  3. =?Utf-8?B?ZGF2ZQ==?=

    Reading Excel sheet from asp.net returns empty cell

    =?Utf-8?B?ZGF2ZQ==?=, Feb 12, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,444
    venkatu2005
    Sep 5, 2009
  4. sajithkahawatta

    read a excel sheet using aspose.excel

    sajithkahawatta, Apr 19, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    524
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 19, 2007
  5. Steve Anderson
    Replies:
    3
    Views:
    239
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page