Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 11th, 2006, 06:18 AM
Authorized User
 
Join Date: Apr 2006
Location: london, , United Kingdom.
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to akshay144
Default EXPORT DATAGRID TO EXCEL FORMATTING PROBLEM

Hi all

I am trying to export a Datagrid to Excel and have been successful to a certain extent.

I am using the code below to export a datagrid to excel which works fine except for one thing. I have a Template column which contains a £ sign like this...Totals (£).
When the user selects the option to open the excel spreadsheet it looks like this Totals (£)

Can anyone help?

CODE:-

private void btn_export_Click(object sender, System.EventArgs e)
        {
            //export to excel
            Response.Clear();
            Response.Buffer= true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.Charset = "";
            this.EnableViewState = false;
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            this.ClearControls(this.dgrd_display_MasterChangeL istWIP);
            this.dgrd_display_MasterChangeListWIP.RenderContro l(oHtmlTextWriter);

            Response.Write(oStringWriter.ToString());

            Response.End();
        }
        private void ClearControls(Control control)
        {
            for (int i=control.Controls.Count -1; i>=0; i--)
            {
                ClearControls(control.Controls[i]);
            }

            if (!(control is TableCell))
            {
                if (control.GetType().GetProperty("SelectedItem") != null)
                {
                    LiteralControl literal = new LiteralControl();
                    control.Parent.Controls.Add(literal);
                    try
                    {
                        literal.Text = (string)control.GetType().GetProperty("SelectedIte m").GetValue(control,null);
                    }
                    catch
                    {

                    }
                    control.Parent.Controls.Remove(control);
                }

                else

                    if (control.GetType().GetProperty("Text") != null)
                {
                    LiteralControl literal = new LiteralControl();
                    control.Parent.Controls.Add(literal);
                    literal.Text = (string)control.GetType().GetProperty("Text").GetV alue(control,null);
                    control.Parent.Controls.Remove(control);
                }
            }
            return;
        }
Reply With Quote
  #2 (permalink)  
Old October 31st, 2006, 12:55 PM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Did you get an answert for this issue. Even i am stuck with this and can't rteally find an answer. Help!
Reply With Quote
  #3 (permalink)  
Old October 31st, 2006, 01:10 PM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Including the line below solved the issue.
Response.ContentEncoding = System.Text.Encoding.Default
Thanks!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
export the contents of Datagrid to Excel file softsea VS.NET 2002/2003 0 October 4th, 2006 02:38 PM
Export to Excel Formatting/Hyperlink HockeyMom SQL Server DTS 0 June 5th, 2006 04:04 PM
export datagrid to excel with configured width sn00pyg4rfi3ld ASP.NET 1.x and 2.0 Application Design 0 October 25th, 2005 05:42 AM



All times are GMT -4. The time now is 07:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.