Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem with displayed excel file created with StringBuilder

Problem with displayed excel file created with StringBuilder

Scheduled Pinned Locked Moved ASP.NET
helpcsharptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aymen hassine
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • A aymen hassine

      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

      J Offline
      J Offline
      Jakob Farian Krarup
      wrote on last edited by
      #2

      That 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups