Problem with displayed excel file created with StringBuilder
-
I have to make an export to excel format, i developed this portion of code with the string builder class of .net to make dynamically the excel file starting from a given DataTable :
StreamWriter SW; SW=File.CreateText("test.xls"); StringBuilder oStringBuilder = new StringBuilder(); foreach(DataRow oDataRow in oDataTable.Rows) { oStringBuilder.Append(""); foreach(DataColumn oDataColumn in oDataTable.Columns) { if (oDataRow[oDataColumn.ColumnName] is long) { oStringBuilder.Append("" + oDataRow[oDataColumn.ColumnName] + ""); } else { oStringBuilder.Append("" + oDataRow[oDataColumn.ColumnName] + ""); } } oStringBuilder.Append(""); }
but when displaying the excel file, i have found some caracters that were badly diplayed like the 'é' that was displayed as 'É'. so how to fix that with that special caracters ? Is there a way to display them with the Append function of the .net Stringbuilder correctly ? thanks in advance -
I have to make an export to excel format, i developed this portion of code with the string builder class of .net to make dynamically the excel file starting from a given DataTable :
StreamWriter SW; SW=File.CreateText("test.xls"); StringBuilder oStringBuilder = new StringBuilder(); foreach(DataRow oDataRow in oDataTable.Rows) { oStringBuilder.Append(""); foreach(DataColumn oDataColumn in oDataTable.Columns) { if (oDataRow[oDataColumn.ColumnName] is long) { oStringBuilder.Append("" + oDataRow[oDataColumn.ColumnName] + ""); } else { oStringBuilder.Append("" + oDataRow[oDataColumn.ColumnName] + ""); } } oStringBuilder.Append(""); }
but when displaying the excel file, i have found some caracters that were badly diplayed like the 'é' that was displayed as 'É'. so how to fix that with that special caracters ? Is there a way to display them with the Append function of the .net Stringbuilder correctly ? thanks in advanceThat sounds like an encoding problem. If I set the encoding to DEFAULT - then it works on my machine.
private void Page\_Load(object sender, System.EventArgs e) { Response.Clear(); Response.ContentEncoding = System.Text.Encoding.Default; Response.ContentType = "application/vnd.ms-excel"; Response.Write("
é
");
Response.End();
}Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't