您好
在我的网站,我有一个GridView和两个按钮,保存在Excel和PDF
,GridView的我可以能够保存,但我试图打印保存Excel工作表的列分拆为不同的cells.I时,试图调整的细胞,但它会是一个很大的过程,哪些客户端不接受。
我想无论是下面的解决方案
solution1:同时保存为Excel,它具有自动以适应适合A4大小的景观印刷
或
解决方案2:
我要提供一个打印按钮直接打印整个页面在横向模式
如何做到这一点
我用下面的代码打印在Excel
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "GOMSNO747.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
//Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in GridView1.Rows)
{
//gvrow.BackColor = Color.White;
if (j <= GridView1.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
我的网页地址是: