473,652 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EnableView State = false;
Response.Clear( );
Response.Buffer = true;
Response.Charse t = "utf-8";
Response.Conten tEncoding = Encoding.GetEnc oding("utf-8");

// Set the content type.
Response.Conten tType = "applicatio n/vnd.ms-excel";

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

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

// Append the page start.
stringBuilder.A ppendFormat("<h tml><head><link href=\"{0}/Styles.css\"
rel=\"styleshee t\" type=\"text/css\" /></head><body>",
Session["RootPath"]);

// Create the html text writer.
HtmlTextWriter htmlTextWriter = new HtmlTextWriter( new
StringWriter(st ringBuilder, CultureInfo.Inv ariantCulture)) ;

// Render the controls.
phrTitle.Render Control(htmlTex tWriter);
phrFinished.Ren derControl(html TextWriter);
dgdData.RenderC ontrol(htmlText Writer);

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

// Write the output.
Response.Write( stringBuilder.T oString());
Response.End();

Any ideas?

Regards

James

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

"Webmills" <ja***@instante commerce.co.uk> wrote in message
news:11******** *************@h 76g2000cwa.goog legroups.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.EnableView State = false;
Response.Clear( );
Response.Buffer = true;
Response.Charse t = "utf-8";
Response.Conten tEncoding = Encoding.GetEnc oding("utf-8");

// Set the content type.
Response.Conten tType = "applicatio n/vnd.ms-excel";

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

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

// Append the page start.
stringBuilder.A ppendFormat("<h tml><head><link href=\"{0}/Styles.css\"
rel=\"styleshee t\" type=\"text/css\" /></head><body>",
Session["RootPath"]);

// Create the html text writer.
HtmlTextWriter htmlTextWriter = new HtmlTextWriter( new
StringWriter(st ringBuilder, CultureInfo.Inv ariantCulture)) ;

// Render the controls.
phrTitle.Render Control(htmlTex tWriter);
phrFinished.Ren derControl(html TextWriter);
dgdData.RenderC ontrol(htmlText Writer);

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

// Write the output.
Response.Write( stringBuilder.T oString());
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
1520
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
1369
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 access the excell document, asp.net seems to still keep it and won't release it. Excell gives some error saying it can't access it, but It's when I terminate the asp.net process in the task manager that the file is then released. I'm wanting to...
0
1101
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 problem. The problem is when I create a new excel file in my application and try and double click it excell starts and has the name of my newly created file however doesn't show any sheets in the xls file. If I shut down the computer and run my...
2
2678
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"); But it works only on save mode but on the display mode still display the name of the page i am calling this excell spread sheet, in other words i see Ratings.aspx in url and in the tab name of this excell spread sheet. I need the name i assigned in the...
2
11919
by: amrhi | last post by:
Hello Guys,....! Can you help me how to export my table to excell using php code ..? thanks alot
2
1545
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 ms-excell. i havent developed any codes since i'm a fresher in .net. i need detailed c# code for this task. pls can any one help...... thanks...
3
2522
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 in the Excell spreadsheet?
2
5723
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
1464
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 all records of excell sheet in a listbox having a title of speecific text like "Names". Thanx >> ALI <<
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8589
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.