Please download the Org.in2bits.MyXls.dll library yourself
1 Public voidGridviewexportexcel (GridView GV)2 {3DataTable dt =NewDataTable ();4 //Add header row5 for(inti =0; I < GV. Columns.count; i++)6 {7 dt. Columns.Add (GV. Columns[i]. HeaderText);8 }9DataRow dr =dt. NewRow ();Ten //Adding data rows One for(inti =0; I < GV. Rows.Count; i++) A { - for(intj =0; J < GV. Rows[i]. Cells.count; J + +) - { theDR[J] =GV. Rows[i]. CELLS[J]. Text; - } - dt. Rows.Add (DR); - } +DataSet Toexcelds =NewDataSet (); - toExcelds.Tables.Add (DT); +Org.in2bits.MyXls.XlsDocument xls =Neworg.in2bits.MyXls.XlsDocument (toexcelds); A This. Page.Response.AddHeader ("content-disposition",string. Format ("Attachment;filename={0}.xls","Export")); at This. Page.Response.Charset ="UTF-8"; - This. Page.Response.ContentEncoding =System.Text.Encoding.Default; - This. Page.Response.ContentType ="Application/ms-excel"; - This. Page.Response.BinaryWrite (XLS). Bytes.bytearray); -}
GridView Data export Excel