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. Datagrid .RenderControl "export to excel" CultureInfo problem

Datagrid .RenderControl "export to excel" CultureInfo problem

Scheduled Pinned Locked Moved ASP.NET
csshelptutorial
4 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.
  • R Offline
    R Offline
    Regardt
    wrote on last edited by
    #1

    Howdy! My web application CultureInfo is forced into a specific Language setting.(en-ZA) My application works perfectly, except if I use the datagrid .RenderControl option to export the grid into excel. The formatting option on the user machine interprets the values (comma's and points) in their current language setting resulting a scrambled data and very interesting results in the excel display. If anybody knows how to force the rendercontrol option into a certain CultureInfo setting or a work around I would really appreciate it. Thanks Regardt Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--

    M 1 Reply Last reply
    0
    • R Regardt

      Howdy! My web application CultureInfo is forced into a specific Language setting.(en-ZA) My application works perfectly, except if I use the datagrid .RenderControl option to export the grid into excel. The formatting option on the user machine interprets the values (comma's and points) in their current language setting resulting a scrambled data and very interesting results in the excel display. If anybody knows how to force the rendercontrol option into a certain CultureInfo setting or a work around I would really appreciate it. Thanks Regardt Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, You may try to set the CurrentCulture at runtime to a specific user setting before exporting the grid to excel, and set it back to normal when the exporting is complete. The sample code looks something like:

      ...
      //Set the current culture of the thread based on the user setting.
      CultureInfo appCultureInfo = Thread.CurrentThread.CurrentCulture;
      string userLang = Request.UserLanguages[0];
      Thread.CurrentThread.CurrentCulture = new CultureInfo(userLang);

      //You code here to do the exporting.
      ...

      //Set back to normal
      Thread.CurrentThread.CurrentCulture = appCultureInfo;
      ...

      R 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, You may try to set the CurrentCulture at runtime to a specific user setting before exporting the grid to excel, and set it back to normal when the exporting is complete. The sample code looks something like:

        ...
        //Set the current culture of the thread based on the user setting.
        CultureInfo appCultureInfo = Thread.CurrentThread.CurrentCulture;
        string userLang = Request.UserLanguages[0];
        Thread.CurrentThread.CurrentCulture = new CultureInfo(userLang);

        //You code here to do the exporting.
        ...

        //Set back to normal
        Thread.CurrentThread.CurrentCulture = appCultureInfo;
        ...

        R Offline
        R Offline
        Regardt
        wrote on last edited by
        #3

        Thanks for the help I'm already setting the CultureInfo on the thread, but the way the excel interprets the data format results in a total different value. I looking for a way to connect the CultureInfo to the page I am using the render the control . ex. of how I render the control With m_Page .Response.Clear() .Response.AddHeader("Content-Disposition", "attachment;filename=" & Title & ".xls") .Response.Buffer = True .Response.ContentType = "application/vnd.ms-excel" .Response.Charset = "" m_Grid.EnableViewState = False Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter) ClearControls(m_Grid) FrontDecorator(oHtmlTextWriter) m_Grid.RenderControl(oHtmlTextWriter) RearDecorator(oHtmlTextWriter) .Response.Write(oStringWriter.ToString()) .Response.End() End With Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--

        M 1 Reply Last reply
        0
        • R Regardt

          Thanks for the help I'm already setting the CultureInfo on the thread, but the way the excel interprets the data format results in a total different value. I looking for a way to connect the CultureInfo to the page I am using the render the control . ex. of how I render the control With m_Page .Response.Clear() .Response.AddHeader("Content-Disposition", "attachment;filename=" & Title & ".xls") .Response.Buffer = True .Response.ContentType = "application/vnd.ms-excel" .Response.Charset = "" m_Grid.EnableViewState = False Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter) ClearControls(m_Grid) FrontDecorator(oHtmlTextWriter) m_Grid.RenderControl(oHtmlTextWriter) RearDecorator(oHtmlTextWriter) .Response.Write(oStringWriter.ToString()) .Response.End() End With Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Can we arrange data in the expected format before doing the exporting? By this I mean instead of trying to apply the user culture setting when rendering the control, you can format data at data binding time in the right format based on the user setting, then you simply run the code to do the exporting after that. So for example when the user clicks the Export button, your application is going to do things like: 1. Bind data to the grid. 2. Apply the the user setting at binding time to the format of data. 3. Export the grid to string. 4. Send back the result to the client

          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