Issues with double quotes when converting ASPX file (HTML format) to excel spreadsheet

  • Thread starter Thread starter desi.american
  • Start date Start date
D

desi.american

I have a dynamically generates ASPX page with tables and data.
Depending on user selection, the same page can be viewed as a simple
web page (rendered in HTML) or as an excel spreadsheet.

If the user chooses to view the page as an excel sheet, I attach the
following line of code in C# in the Page_Load method.
Response.ContentType = "application/vnd.ms-excel";

All this works fine. But some of cells read nvarchar fields from a
database which may contain double quotes ("). The cells with double
quotes dont have a problem when they are rendered in plain web page
format (HTML)
Sample:
This is an "example" of the cell contents in HTML format.

But when I choose to render the web page in Excel format as mentioned
above, the cells with the double quotes (") get messed up and render
garbage characters (“) in place of the double quotes (")
Sample"
This is an “example“ of the cell contents in the Excel
spreadsheet format.

I've no clue as to why this is happening. I tried replacing the double
quotes (") with a single quote (') using the .Replace() method for
strings and that seems to alleviate the problem. But I'm not sure if
this is an acceptable or viable solution for the long term.

Does anyone have an idea why this happen? All comments/suggestions
welcome. Thank you in advance.
 
Addition to above post:
The garbage character are showing up as double quotes in this post. So
much for me trying to explain the problem. Our clients use IE 6.0.
This is what the garbage look like (a^Ece) or something like that.
 
Back
Top