Last post Aug 04, 2010 05:15 AM by sirdneo
None
0 Points
4 Posts
Mar 17, 2010 05:00 AM|coolsanu|LINK
Hi ,
I have a requirement where i need to export the gridview data to excel.My code export the data in excel that was fine.
But the enchancement needed now , I was exporting the 3 gridview in same excel sheet under the workbook.
Now i need to export the 3 grid view in 3 different sheet in the same workbook.
so can please tell or share the updated code in my below code ...
public void writeovrsummary() {
Response.Write("<BR>");
Response.Write("Overall Summary"); //Response.Write("<BR>"); //Response.Write("Report as of " + DateTime.Now.ToString("hh:mm ss tt"));
StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw);
SqlCommand com = MyConnection.CreateCommand(); com.CommandText = "useroverall_Report"; SqlParameter[] par = new SqlParameter[1]; par[0] = new SqlParameter("@USERID", SqlDbType.Int); par[0].Value = UserId; com.Parameters.AddRange(par);
SqlParameter[] par1 = new SqlParameter[1]; par1[0] = new SqlParameter("@project_id", SqlDbType.VarChar, 10); par1[0].Value = Session["projectid"].ToString(); com.Parameters.AddRange(par1); com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter MyAd = new SqlDataAdapter(com); DataTable dt = new DataTable(); MyAd.Fill(dt); gvprjreport.DataSource = dt; //gvprjreport.AllowPaging = false; gvprjreport.DataBind();
//Change the Header Row back to white color gvprjreport.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Apply style to Individual Cells gvprjreport.HeaderRow.Cells[0].Style.Add("background-color", "#507CD1"); gvprjreport.HeaderRow.Cells[1].Style.Add("background-color", "#507CD1"); gvprjreport.HeaderRow.Cells[2].Style.Add("background-color", "#507CD1"); gvprjreport.HeaderRow.Cells[3].Style.Add("background-color", "#507CD1");
for (int i = 0; i < gvprjreport.Rows.Count; i++) { GridViewRow row = gvprjreport.Rows[i];
//Change Color back to white row.BackColor = System.Drawing.Color.White;
//Apply text style to each Row row.Attributes.Add("class", "textmode");
//Apply style to Individual Cells of Alternating Row if (i % 2 != 0) { row.Cells[0].Style.Add("background-color", "#EFF3FB"); row.Cells[1].Style.Add("background-color", "#EFF3FB"); row.Cells[2].Style.Add("background-color", "#EFF3FB"); row.Cells[3].Style.Add("background-color", "#EFF3FB");
} } gvprjreport.RenderControl(hw);
//style to format numbers to string //string style = @"<style> .textmode { mso-number-format:\@; } </style>"; //Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); }
kindly help me as soon as possible
thank you,
grid view
Mar 19, 2010 05:16 AM|coolsanu|LINK
Hi can anyone please help out...
Star
8012 Points
2124 Posts
Mar 30, 2010 06:55 AM|sumitd|LINK
Refer below articles:
http://www.codeproject.com/KB/office/ExportDataSetToExcel.aspx
http://www.codeproject.com/KB/aspnet/Export_to_Excel.aspx
10444 Points
2463 Posts
Aug 04, 2010 05:15 AM|sirdneo|LINK
Try this link, it tells how to export datatable to excel,without using datagrid, also you can format the data as per your requirements:-
http://zeeshanumardotnet.blogspot.com/2010/07/export-to-excel-in-net.html
None
0 Points
4 Posts
Export Gridview data to Excel sheet
Mar 17, 2010 05:00 AM|coolsanu|LINK
Hi ,
I have a requirement where i need to export the gridview data to excel.My code export the data in excel that was fine.
But the enchancement needed now , I was exporting the 3 gridview in same excel sheet under the workbook.
Now i need to export the 3 grid view in 3 different sheet in the same workbook.
so can please tell or share the updated code in my below code ...
public void writeovrsummary()
{
Response.Write("<BR>");
Response.Write("Overall Summary");
//Response.Write("<BR>");
//Response.Write("Report as of " + DateTime.Now.ToString("hh:mm ss tt"));
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
SqlCommand com = MyConnection.CreateCommand();
com.CommandText = "useroverall_Report";
SqlParameter[] par = new SqlParameter[1];
par[0] = new SqlParameter("@USERID", SqlDbType.Int);
par[0].Value = UserId;
com.Parameters.AddRange(par);
SqlParameter[] par1 = new SqlParameter[1];
par1[0] = new SqlParameter("@project_id", SqlDbType.VarChar, 10);
par1[0].Value = Session["projectid"].ToString();
com.Parameters.AddRange(par1);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter MyAd = new SqlDataAdapter(com);
DataTable dt = new DataTable();
MyAd.Fill(dt);
gvprjreport.DataSource = dt;
//gvprjreport.AllowPaging = false;
gvprjreport.DataBind();
//Change the Header Row back to white color
gvprjreport.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Apply style to Individual Cells
gvprjreport.HeaderRow.Cells[0].Style.Add("background-color", "#507CD1");
gvprjreport.HeaderRow.Cells[1].Style.Add("background-color", "#507CD1");
gvprjreport.HeaderRow.Cells[2].Style.Add("background-color", "#507CD1");
gvprjreport.HeaderRow.Cells[3].Style.Add("background-color", "#507CD1");
for (int i = 0; i < gvprjreport.Rows.Count; i++)
{
GridViewRow row = gvprjreport.Rows[i];
//Change Color back to white
row.BackColor = System.Drawing.Color.White;
//Apply text style to each Row
row.Attributes.Add("class", "textmode");
//Apply style to Individual Cells of Alternating Row
if (i % 2 != 0)
{
row.Cells[0].Style.Add("background-color", "#EFF3FB");
row.Cells[1].Style.Add("background-color", "#EFF3FB");
row.Cells[2].Style.Add("background-color", "#EFF3FB");
row.Cells[3].Style.Add("background-color", "#EFF3FB");
}
}
gvprjreport.RenderControl(hw);
//style to format numbers to string
//string style = @"<style> .textmode { mso-number-format:\@; } </style>";
//Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
}
kindly help me as soon as possible
thank you,
grid view
sandy
None
0 Points
4 Posts
Re: Export Gridview data to Excel sheet
Mar 19, 2010 05:16 AM|coolsanu|LINK
Hi can anyone please help out...
sandy
Star
8012 Points
2124 Posts
Re: Export Gridview data to Excel sheet
Mar 30, 2010 06:55 AM|sumitd|LINK
Refer below articles:
http://www.codeproject.com/KB/office/ExportDataSetToExcel.aspx
http://www.codeproject.com/KB/aspnet/Export_to_Excel.aspx
Visit: www.msblogdirectory.com
www.dotnetspeaks.com
Star
10444 Points
2463 Posts
Re: Export Gridview data to Excel sheet
Aug 04, 2010 05:15 AM|sirdneo|LINK
Try this link, it tells how to export datatable to excel,without using datagrid, also you can format the data as per your requirements:-
http://zeeshanumardotnet.blogspot.com/2010/07/export-to-excel-in-net.html
Zeeshan Umar
~Please Mark As Answer, one or multiple posts, which helped you. So that it might be useful for others~