473,512 Members | 15,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Carriage Returns

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 12 '05 #1
3 3567


st@jpa.co.jp wrote:

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


You could start with creating a spreadsheet in Excel with a cell that
has multiline content and then save/export that as XML. Then look at the
source of the XML and have your .NET create exectly the same element,
attributes and content when you need a multiline cell.

There is also an office.xml group on this server where perhaps someone
is familiar with the Excel XML format.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
<st@jpa.co.jp> wrote in message news:11**********************@g49g2000cwa.googlegr oups.com...
"Name \r\nAddress1\r\nAddress2 \r\nAddress3 \r\nAddress4\r\n" : : <Cell ss:StyleID="s26"><Data ss:Type="String">
Name
Address1 : : And what appears in the address cell of the Excel sheet is:
Name Address1 Address 2 Address 3 Address 4


Excel is normalizing the whitespace in your <Data> tag. Normalization
is the process of reducing all contiguous whitespace, linefeeds and
carriage returns into a single space.

Instead of '\n' you should put the character entity ref "&#xa;" in there
which represents a linefeed (same as pressing ALT-ENTER in Excel).

You also need to make sure that Excel knows that the cell is supposed
to contain multi-line text, otherwise it will display your linefeeds as a
control character (a skinny rectangle, usually). To get around this,
make sure that the <Style> tag identified by ss:StyleID = "26" has
an <Alignment> specifying at least:

<Alignment ss:WrapText="1"/>

This will ensure that Excel treats any cell data associated with that Style
as multiline text.
Derek Harmon
Nov 12 '05 #3


Derek Harmon wrote:

Excel is normalizing the whitespace in your <Data> tag. Normalization
is the process of reducing all contiguous whitespace, linefeeds and
carriage returns into a single space.
But that should only happen for certain attribute values, why should
line feeds in element content be normalized to a single space?
Instead of '\n' you should put the character entity ref "&#xa;" in there
which represents a linefeed (same as pressing ALT-ENTER in Excel).


Would you know any way with DOM/XmlDocument in .NET to make sure that a
text node contains a numeric character reference &#xA; when serialized
and not the character linefeed itself?
Maybe an extension of XmlTextWriter which overrides WriteString to do
some WriteRaw instead with the original argument having "\n" escaped as
"&#xA;" could achieve that. Or is there a simpler way?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7308
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
2
4115
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the...
2
2927
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this...
12
5591
by: Nimmy | last post by:
Hi, I have a data file and I want to remove Carriage returns. Any one has any C code/program which does this? I am working on Windows XP machine.....I don't have access to UNIX machine. But I...
2
2321
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost...
8
2207
by: TheDude5B | last post by:
Hi, I have some data which is stored in my MySQL database as TEXT. when the data is entered in, it has some carriage returns in it, and this can be seen when querying the data using MySQL Query...
7
11164
by: mattrapoport | last post by:
I have a page with a div on it. The div displays a user comment. When the user logs into this page, their current comment is pulled from a db and displayed in the div. The user can edit the...
2
4639
by: GregBeagle | last post by:
Windows XP I have a simple form from which I want to generate an email with the contents of the form. I use carriage returns to format the content for readability. When I test it on my computer...
0
1393
by: markus.shure | last post by:
Hi, I'm noticed a problem testing a JAX-WS client with a WSE server. The JAX-WS client adds carriage returns to a SOAP header element that is signed. This causes the WSE server to raise an...
11
12556
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.