473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Export to Excell

Hi

I am exporting a datagrid to Excel using the code as below. The problem
that I am experiencing is that if my datagrid includes  
characters, spurious A with an accent characters appear within the
export. I am certain that this should be remedied by changin the
charset and/or encoding, but I cannot seem to get it right.

// Set up the page for export.
this.EnableViewState = false;
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.ContentEncoding = Encoding.GetEncoding("utf-8");

// Set the content type.
Response.ContentType = "application/vnd.ms-excel";

// Set the title.
Response.AddHeader("content-disposition", "attachment; filename=" +
TITLE + ".xls");

// Create the string builder.
StringBuilder stringBuilder = new StringBuilder();

// Append the page start.
stringBuilder.AppendFormat("<html><head><link href=\"{0}/Styles.css\"
rel=\"stylesheet\" type=\"text/css\" /></head><body>",
Session["RootPath"]);

// Create the html text writer.
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new
StringWriter(stringBuilder, CultureInfo.InvariantCulture));

// Render the controls.
phrTitle.RenderControl(htmlTextWriter);
phrFinished.RenderControl(htmlTextWriter);
dgdData.RenderControl(htmlTextWriter);

// Append the page end.
stringBuilder.Append("</body></html>");

// Write the output.
Response.Write(stringBuilder.ToString());
Response.End();

Any ideas?

Regards

James

Jun 11 '06 #1
1 1784
There is a good sample by Steve here at:-
http://steveorr.net/articles/ExcelExport.aspx
Patrick

"Webmills" <ja***@instantecommerce.co.uk> wrote in message
news:11*********************@h76g2000cwa.googlegro ups.com...
Hi

I am exporting a datagrid to Excel using the code as below. The problem
that I am experiencing is that if my datagrid includes &nbsp;
characters, spurious A with an accent characters appear within the
export. I am certain that this should be remedied by changin the
charset and/or encoding, but I cannot seem to get it right.

// Set up the page for export.
this.EnableViewState = false;
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.ContentEncoding = Encoding.GetEncoding("utf-8");

// Set the content type.
Response.ContentType = "application/vnd.ms-excel";

// Set the title.
Response.AddHeader("content-disposition", "attachment; filename=" +
TITLE + ".xls");

// Create the string builder.
StringBuilder stringBuilder = new StringBuilder();

// Append the page start.
stringBuilder.AppendFormat("<html><head><link href=\"{0}/Styles.css\"
rel=\"stylesheet\" type=\"text/css\" /></head><body>",
Session["RootPath"]);

// Create the html text writer.
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new
StringWriter(stringBuilder, CultureInfo.InvariantCulture));

// Render the controls.
phrTitle.RenderControl(htmlTextWriter);
phrFinished.RenderControl(htmlTextWriter);
dgdData.RenderControl(htmlTextWriter);

// Append the page end.
stringBuilder.Append("</body></html>");

// Write the output.
Response.Write(stringBuilder.ToString());
Response.End();

Any ideas?

Regards

James

Jun 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andy48 | last post by:
Hi everyone, Can anyone point me in the direction of how to export a table, in excell format automatically via E-Mail? regards Andy48
2
by: Robert Halstead | last post by:
Hi guys, I have a asp.net web app and it's connecting to an excell 2003 document (in another folder) via OleDataAdapter. Everything works and all, it's just that when I shutdown IE and try to...
0
by: Delforce | last post by:
Hi all, My application allows you to create a new excel file and then double click it in the list view to start it in excell. If the excell file is an existing one then I can start it now...
2
by: glibo | last post by:
I am trying to change the tab name when i open a excell spread sheet on the run time in c#. I changed it in the code: Response.AddHeader("content-disposition","filename=" + sFileName + ".xls");...
2
by: amrhi | last post by:
Hello Guys,....! Can you help me how to export my table to excell using php code ..? thanks alot
2
by: jiaudheen | last post by:
hi i have a gridview which has 5 columns and atleast 100 rows. i enabled sorting and paging. totally i have 10 rows in a page and hence i have 10 pages. i need to export ths grid view to a...
3
by: cmdolcet69 | last post by:
What would be the easiest way to export a graphic (I have yet to determine what type of graphic, .jpg, bitmap....) however im open to suggestion, also how can i export my graphic so that it appear...
2
nirmalsingh
by: nirmalsingh | last post by:
hai all, i need to export datagridview contents to a excell sheet including header. can anyone help me with sample code in c#. thanx in advance with Cheers Nirmal
1
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, I m creating a database. The data for database will fetched from an excell sheet. Now how can i read an excell sheet and update my database with that excell sheet. Or I want to show...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.