PC Review


Reply
Thread Tools Rate Thread

c# export to excel and preserve carriage returns inside cell

 
 
Bryan Ax
Guest
Posts: n/a
 
      19th Jul 2006
I'm trying to fix a bug in someone else's code. He's got a string saved
in a database such as:

<xsl:variable name="Var1">
<xsl:choose>
<xsl:when test="@SomeAttribute &gt; 1'">
<xsl:value-of select="'Y'"/>
</xsl:when>
<xsltherwise>
<xsl:value-of select="'N'"/>
</xsltherwise>
</xsl:choose>
</xsl:variable>

I'm trying to export this value from the database to Excel, and
maintain the carriage returns inside a cell in Excel. I found that in
order to have the xsl appear in the cell, I had to call
Server.HtmlEncode on the value that comes back from the database, but
have not found a means to replace the \r\n that I see in my string
value in C# with a value that Excel will like to create line breaks
inside of the cell.

The code is not working directly with an Excel object, but instead is
filling a result set into a datagrid and then streaming the datagrid to
an excel workbook using:

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = string.Empty;

System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new
System.Web.UI.HtmlTextWriter(sw);
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();

Any ideas?

Bryan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Text with Carriage Returns inside cell values Ryan L Microsoft Excel Misc 2 14th May 2009 08:58 PM
Importing Text with Carriage Returns inside cell values Ryan L Microsoft Excel Misc 0 14th May 2009 07:34 PM
Preserve carriage returns in RichTextBox control Bill Microsoft Dot NET 3 2nd Dec 2008 05:28 PM
how do i format carriage returns for each cell in excel? =?Utf-8?B?TGF1cmVsIEh1bnRlcg==?= Microsoft Excel Misc 1 5th Sep 2006 02:48 PM
How can I enter carriage returns into text within a cell in excel =?Utf-8?B?TGl6enk=?= Microsoft Excel Misc 3 17th Nov 2005 07:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:36 AM.