Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Euro

Status
Not open for further replies.

Matsul

IS-IT--Management
May 6, 2002
140
BE
Exporting to excel (VS 2005 .Net c#), I am having problems with the €.

10660 56660 € 158,58 € 158,58
is becoming
10660 56660 € 158,58 € 158,58

It is the footer of a grid, extracted using

if (gv.FooterRow != null)
{
GridViewExportUtil.PrepareControlForExport(gv.FooterRow);
table.Rows.Add(gv.FooterRow);
}

Any ideas what can be done ?

thanks


 
you may need to set the encoding type. UTF16 or UTF8. This is where I would start.

excel has it's own set of formatting, so another option would be to export only the data to excel and set format properties in excel.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I tried

HttpContext.Current.Response.Charset = "UTF-16";

(as below) and some others but still no luck.

thanks.


public class GridViewExportUtil
{
/// <summary>
///
/// </summary>
/// <param name="fileName"></param>
/// <param name="gv"></param>
public static void Export(string fileName, GridView gv)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader(
"content-disposition", string.Format("attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Charset = "UTF-16";

using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// Create a form to contain the grid
Table table = new Table();

// add the header row to the table
if (gv.HeaderRow != null)
{
GridViewExportUtil.PrepareControlForExport(gv.HeaderRow);
table.Rows.Add(gv.HeaderRow);
}

// add each of the data rows to the table
foreach (GridViewRow row in gv.Rows)
{
GridViewExportUtil.PrepareControlForExport(row);
table.Rows.Add(row);
}

// add the footer row to the table
if (gv.FooterRow != null)
{
GridViewExportUtil.PrepareControlForExport(gv.FooterRow);
table.Rows.Add(gv.FooterRow);
}

// render the table into the htmlwriter
table.RenderControl(htw);

// render the htmlwriter into the response
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top