Strange characters - help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Code Monkey

    #1

    Strange characters - help needed

    I'm exporting the contents of a GridView (in C# v2) into Excel.

    However, whilst the GridView displays on the web page correctly, when
    the data is in Excel, I get a lot of  characters appearing ('A' with
    a hat on top) where there are numbers (ie; order numbers and line
    totals).

    Is there an easy way to remove these?
    The code I'm using looks like:


    <code>
    protected void btn_export_Clic k(object sender, EventArgs e)
    {
    Response.Clear( );
    String fileName = Invoice";
    Response.AddHea der("content-disposition",
    string.Format(" attachment;file name={0}.xls", fileName));
    Response.Charse t = "";
    Response.Conten tType = "applicatio n/vnd.xls";
    Response.Write( sb.ToString());
    Response.Write( Session["ExcelDataG rid"].ToString());
    Response.End();
    }
    </code>

    and I've got
    <code>
    <globalizatio n requestEncoding ="utf-8" responseEncodin g="utf-8"
    culture="en-GB"/>
    </code

    in my web.config file.

  • Mr Icekirby

    #2
    RE: Strange characters - help needed

    The code you supplied does not help identify the problem.

    We do not know what type "Response" is.

    "Code Monkey" wrote:
    I'm exporting the contents of a GridView (in C# v2) into Excel.
    >
    However, whilst the GridView displays on the web page correctly, when
    the data is in Excel, I get a lot of  characters appearing ('A' with
    a hat on top) where there are numbers (ie; order numbers and line
    totals).
    >
    Is there an easy way to remove these?
    The code I'm using looks like:
    >
    >
    <code>
    protected void btn_export_Clic k(object sender, EventArgs e)
    {
    Response.Clear( );
    String fileName = Invoice";
    Response.AddHea der("content-disposition",
    string.Format(" attachment;file name={0}.xls", fileName));
    Response.Charse t = "";
    Response.Conten tType = "applicatio n/vnd.xls";
    Response.Write( sb.ToString());
    Response.Write( Session["ExcelDataG rid"].ToString());
    Response.End();
    }
    </code>
    >
    and I've got
    <code>
    <globalizatio n requestEncoding ="utf-8" responseEncodin g="utf-8"
    culture="en-GB"/>
    </code>
    >
    in my web.config file.
    >
    >

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Strange characters - help needed

      Code Monkey <dlynes2005@gma il.comwrote:
      I'm exporting the contents of a GridView (in C# v2) into Excel.

      However, whilst the GridView displays on the web page correctly, when
      the data is in Excel, I get a lot of  characters appearing ('A' with
      a hat on top) where there are numbers (ie; order numbers and line
      totals).

      Is there an easy way to remove these?
      I believe the problem is that you're writing it as a *string* - Excel
      spreadsheets aren't typically text data. Open one in Notepad...

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      Working...