Friday, March 6, 2009

Exporting Euro symbol in excel from asp.net.

I was working with exporting GridView to Excel. GridView contains one column that has currency symbols. After exporting to excel all currency were displaying correctly but Euro() symbols got converted to something other characters like this "€" . After searching on internet i got solution. below is the solution.


public void ExportExcel(string filename, GridView gv)
{
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".xls");
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
string output = sw.ToString();
//////////////////////
byte[] euroByte = new byte[1];
euroByte[0] = (byte)128;
bool isAfterFirst = false;
foreach (string item in output.Split('€'))
{
if (isAfterFirst)
{
Response.OutputStream.Write(euroByte, 0, 1);
}
Response.Write(item);
Response.Flush();
isAfterFirst = true;
}
Response.Write("\r\n");
//////////////////////
Response.End();
}

6 comments:

Anonymous said...

Thank you very much: I also had your problem, i tryed your solution and it works excellently!

Anonymous said...

Hey,

When ever I surf on web I never forget to visit this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]Plenty of useful information on aspnetachives.blogspot.com. Do you pay attention towards your health?. Here is a fact for you. Recent Research presents that nearly 60% of all United States grownups are either obese or weighty[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Therefore if you're one of these citizens, you're not alone. In fact, most of us need to lose a few pounds once in a while to get sexy and perfect six pack abs. Now the question is how you are planning to have quick weight loss? [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss[/url] is really not as tough as you think. You need to improve some of you daily habbits to achive weight loss in short span of time.

About me: I am webmaster of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also mentor who can help you lose weight quickly. If you do not want to go under painful training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for fast weight loss.

大人の出会い said...

大人の出会いで大興奮!素敵な一夜を共に過ごせるパートナーを探しませんか?割り切った関係、肉体関係だけでもOK!

Hugo said...

Excellent!
That's the exact solution for my problem!!

Thank you a lot!

Amy Carry said...

turn the handle: Good Shower faucet handle in the rotation, there is no switch over between the Pull down kitchen faucet and the gap opened and closed easily unrestricted, non-skid. Not only can poor quality Bathroom accessories gap, blocked feeling too great.

Xin Chen said...

Custom Made Gemstones Rings,Jewelry in Myraygem.http://www.myraygem.com/