Gridview直接打印或Excel调整以A4尺寸页面打印 [英] Gridview directly printing or Excel Adjust for printing in A4 size page

查看:136
本文介绍了Gridview直接打印或Excel调整以A4尺寸页面打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的网站上,我有一个gridview和两个按钮,用于将那个gridview保存到Excel和Pdf
我可以保存一个,但是当我尝试打印保存的Excel工作表时,列会拆分为不同的单元格.我试图调整单元格,但这将是客户不接受的一个大过程.
我想要任何一种休闲的解决方案
解决方案1:在另存为Excel的同时,它必须自动适合A4尺寸的横向打印



解决方案2:
我必须提供一个打印按钮,以横向模式直接打印整个页面

怎么做

我使用了休闲代码在Excel中打印

Hi
in my website i have a gridview and two buttons to save that gridview in Excel and Pdf
i can able to save that one but when i trying to print the saved excel sheet the columns are splitted to the different cells.I tried to adjust the cells but it will be a big process which client didnt accept.
I want either of the fallowing solutions
solution1:while saving the as Excel it has to fit automatically fit for A4 size Landscape printing

OR

solution 2:
I have to provide a print button which prints directly the whole page in Landscape mode

How to do that

I used the fallowing code to print in 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();



我的专页地址是:
http://ulchyd.in/GOMSNO747.aspx [



my Page Address is:
http://ulchyd.in/GOMSNO747.aspx[^]

推荐答案

这对我来说可以用所需的纸张尺寸进行打印

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printersettings.papersizes.aspx
This worked for me for printing in the required paper size

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printersettings.papersizes.aspx


这篇关于Gridview直接打印或Excel调整以A4尺寸页面打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆