Microsoft Excel
--
Questions
--
Followers
Top Experts
private static void FileDownloadPrompt(string FileName, SqlDataReader reader, string ContentType, string FileExtension)
{
//set the conttent type of the file to be downloaded
System.Web.HttpContext.Cur
//add the response headers
System.Web.HttpContext.Cur
//add the contents of the result set to the response stream
System.Web.HttpContext.Cur
//end the http response
System.Web.HttpContext.Cur
}
private static string ToHTMLTable(SqlDataReader iDr)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(
//check to see if there the reader has columns
if (iDr.FieldCount != 0)
{
sb.Append("<table border=1><tr>");
//loop thru each column
for (int i = 0; i < iDr.FieldCount; i++)
{
sb.Append("<td>" + Convert.ToString(iDr.GetNa
}
sb.Append("</tr><tr>");
//loop until the record reaches eol(end of line)
while (iDr.Read())
{
//loop thru each column, this is necessesary so that we could map
//the columns to their proper place
for (int i = 0; i < iDr.FieldCount; i++)
{
sb.Append("<td>" + Convert.ToString(iDr.GetVa
}
sb.Append("</tr><tr>");
}
sb.Remove(sb.ToString().La
}
//return our stringbuilder
return sb.ToString();
}
After export to excel is showing characters are exranos
1. NumeroDocumento column must be of type text
2. NumeroSentencia column is showing strange characters, the text to be displayed is "N° de la sentencia"
3. DecisionSuperior column is showing strange characters, the text to be displayed is "Decisión Superior"
I attached this file
errorExcel.JPG
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
1. Assign this style to your data cells: <td style="mso-number-format:\
2, 3. Set the character encoding to Unicode. Add the following lines after adding the content-disposition header.
System.Web.HttpContext.Cur
System.Web.HttpContext.Cur
I try this
sb.Append("<td style="mso-number-format:\
but i have this error:
Error 4 Unexpected character '\'






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
If you need a \ in a C# string, then you need to use \\
\ is a special character in C#... \n is newline, for example, so if you want a literal \ in your string, you must double it.
Hope that helps,
Jake
you can use them in your code like this:
sb.Append("<td style=\"mso-number-format:
Here are all the different styles you can use while exporting data to excel:
.currency {mso-number-format:Currenc
.currencybold { mso-number-format:Currency
.number0dec {mso-number-format:"0"}
.number2dec {mso-number-format: Fixed;}
.number4dec {mso-number-format:"0\.000
.number6dec {mso-number-format:"0\.000
.number4decbold {mso-number-format:"0\.000
.number2decbold {mso-number-format: Fixed; font-weight:700;}
.text {mso-number-format:General
.textnowrap {mso-number-format:General
.num2text {mso-style-parent:text; mso-number-format:"\@";whi
.shortdate{mso-number-form
.MMYY {mso-number-format:"MM/YY"
.MMDDYY {mso-number-format:"m/d/yy
.monthyear {mso-number-format:"\[ENG\
.rotateup {mso-rotate:90}
.excel_bottom_border{borde
.excel_top_border{border-t
// to use formula in Excel
<td>=sum(a1:a4)</td>

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
sb.Append("<td style=\"mso-number-format:
buy i have te same error (view yellow column)
U might have to convert it in long integer and the convert to string for excel export.
Let me know...






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Microsoft Excel
--
Questions
--
Followers
Top Experts
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.