export grid to excel

Posted by Suneel161 under Regular Expressions on 4/28/2010 | Views : 2277 | Status : [Member] | Replies : 6
hii
i'm exporting grid to excel.i,ve one column in grid 'Phone no', its length is 12 numbers.
i give 12 numbers,
then i exporting to excel,the phone no displaying different formate.
if i give 10 numbers it displays correct.how to solve this problem




Responses

Posted by: Pavanandey on: 4/28/2010 [Member] Bronze

Up
0
Down


Hi,

since when u export the gridview to excel the excel takes every coloum as an object and spefic type is not set to it, select the column in the excel and format it to numbers.

Hope this solves ur problem

Thanks
Pavan Kumar
Mark Answer if this fits the need

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Suneel161 on: 4/28/2010 [Member] Starter

Up
0
Down
hii pavanandey

can give example


Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 4/28/2010 [Member] Starter
Posted by: Naveenmanam on: 4/28/2010 [Member] Starter

Up
0
Down
example:
public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{



}



//Double click your Button and write the below code to Export Gridview Data to Excel

protected void Button1_Click(object sender, EventArgs e)

{

TextWriter sw = new StreamWriter(@"F:\\ExcelData.xls");

//Getting the Gridview HeaderRow Values

sw.WriteLine(GridView1.HeaderRow.Cells[0].Text+"\t"+GridView1.HeaderRow.Cells[1].Text+"\t"

+GridView1.HeaderRow.Cells[2].Text);



for (int i = 0; i < GridView1.Rows.Count; i++)

{

//Getting the Gridview Row values

sw.WriteLine(GridView1.Rows[i].Cells[0].Text + "\t " + GridView1.Rows[i].Cells[1].Text + "\t" + GridView1.Rows[i].Cells[2].Text );

}

sw.Close();//Don't Forget to Close the StreamWrtier object.

}

}

NaveenKumar

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Er.deepakdalal on: 4/28/2010 [Member] Starter

Up
0
Down
Hi Suneel161


try the attached class file, i hope it will help you in this problem. I am found this on the www.codeproject.com
 Download source file

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 4/28/2010 [Member] Starter

Up
0
Down
Check this link to set a column width of excel,www.microsoft.com/en-us/excel/HP051988131033.aspx

Syed Shakeer Hussain

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response