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