By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

export to excel

P: n/a
Hi all,
I'm exporting a datagrid to an excel file.
I'm using the following source code to export.
DataTable dt = new DataTable();
DataAccess.StoredProcedure sproc = new
DataAccess.StoredProcedure("sproc_getdata");

sproc.Run(dt);

DataGrid1.DataSource = dt;

DataGrid1.DataBind();

DataGrid1.EnableViewState = false;

DataGrid1.Visible = true;

DataGrid1.GridLines = GridLines.Both;

Response.Clear();

Response.Buffer = true;

Response.AddHeader( "Content-Disposition", "filename=File1.xls");
StringWriter stringWriter = new StringWriter();

HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

DataGrid1.RenderControl(htmlWriter);

Response.Write(stringWriter.ToString());

Response.ContentType="application/vnd.ms-excel";

Response.End();

Its working fine.

but there is an isuue datagrid dt contains extended language
strings (like chinese, japanese).These strings are not getting
exported to excel .
DataGrid is getting data from SQLServer2005 database. I know that
sqlserver is using utf-16 encoding for unicode character. So i've tried
to change Response.ContentEncoding to utf-16. But it is also not
working.

Can anyone help me.

Sep 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Depending what you really want to do when exporting to Excel, I always found
it much easier to use a third-party tool. I believe ComponentOne has a dll
that will do the trick.

David

======================================
David McCarter
www.vsdntips.com
VSDN Tips & Tricks .NET Coding Standards available at:
www.cafepress.com/vsdntips.20412485
"elangovan" wrote:
Hi all,
I'm exporting a datagrid to an excel file.
I'm using the following source code to export.
DataTable dt = new DataTable();
DataAccess.StoredProcedure sproc = new
DataAccess.StoredProcedure("sproc_getdata");

sproc.Run(dt);

DataGrid1.DataSource = dt;

DataGrid1.DataBind();

DataGrid1.EnableViewState = false;

DataGrid1.Visible = true;

DataGrid1.GridLines = GridLines.Both;

Response.Clear();

Response.Buffer = true;

Response.AddHeader( "Content-Disposition", "filename=File1.xls");
StringWriter stringWriter = new StringWriter();

HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

DataGrid1.RenderControl(htmlWriter);

Response.Write(stringWriter.ToString());

Response.ContentType="application/vnd.ms-excel";

Response.End();

Its working fine.

but there is an isuue datagrid dt contains extended language
strings (like chinese, japanese).These strings are not getting
exported to excel .
DataGrid is getting data from SQLServer2005 database. I know that
sqlserver is using utf-16 encoding for unicode character. So i've tried
to change Response.ContentEncoding to utf-16. But it is also not
working.

Can anyone help me.

Oct 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.