Problem with export to excel column format

C

CDonlan

Here is how im exporting
Code:
 //Clear response content and headers
            response.Clear();
            response.ClearContent();
            response.ClearHeaders();

            //Add header
            response.AddHeader("content-disposition",
"attachment;filename=" + fileName + ".xls");

            response.Charset = string.Empty;
            response.Cache.SetCacheability(HttpCacheability.Public);
            response.ContentType = "application/vnd.ms-excel";

            //Create StringWriter
            StringWriter stringWrite = new StringWriter();

            //Create HtmlTextWriter
            HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);

            //Remove controls from Column Headers
            if (grdView.HeaderRow != null && grdView.HeaderRow.Cells !
= null)
            {
                for (int ct = 0; ct < grdView.HeaderRow.Cells.Count; ct
++)
                {
                    //Save header text if found
                    string headerText =
grdView.HeaderRow.Cells[ct].Text;

                    //Check for controls in header
                    if (grdView.HeaderRow.Cells[ct].HasControls())
                    {
                        //Check for link buttons (used in sorting)
                        if
(grdView.HeaderRow.Cells[ct].Controls[0].GetType().ToString() ==
"System.Web.UI.WebControls.DataControlLinkButton")
                        {
                            //Link button found, get text
                            headerText =
((LinkButton)grdView.HeaderRow.Cells[ct].Controls[0]).Text;
                        }
                        //Remove controls from header
                        grdView.HeaderRow.Cells[ct].Controls.Clear();
                    }

                    //Reassign header text
                    grdView.HeaderRow.Cells[ct].Text = headerText;
                }
            }

            //Remove unwanted columns (header text listed in
removeColumnList arraylist)
            if (excludedColumnList != null)
            {
                foreach (DataControlField field in grdView.Columns)
                {
                    if (excludedColumnList.Contains(field.HeaderText))
                    {
                        field.Visible = false;
                    }
                }
            }

            //Call GridView's RenderControl method
            grdView.RenderControl(htmlWrite);

            //Add style to ensure that numeric data treated as text
will retain the leading zeros.
            string style = @"<style> .zeroLeftPad { mso-number-format:
\@; } </style> ";
            response.Write(style);

            //Write Response to browser
            response.Write(stringWrite.ToString());

            response.End();

I have a bound field thats of type string. It can be a combination of
letters and number. When ever that string is 1-1 ,2-3, 3-4, etc.. It
converts that to a date , like 1-Jan. Is there a way to prevent this?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top