日期:2014-05-17  浏览次数:20599 次

[求助].net 把页面的内容导出为word 如何设置word的页边距
目前我已经能导出word了

 protected void outword_Click()
    {
        //Word 
        string strFileName = "入库单-" + ins_idtb.Text;
        //string httpHeader = "attachment;filename= " + HttpUtility.UrlEncode(strFileName + ".doc");
        //Response.AppendHeader("Content-Disposition ", httpHeader); 

        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName + ".doc") + "");
        Response.ContentType = "application/ms-word";
        Response.Charset = "UTF-8";
        Response.ContentEncoding = System.Text.Encoding.UTF8;

        //关闭控件的视图状态 
        out_word.EnableViewState = false;
        //初始化HtmlWriter 
        System.IO.StringWriter writer = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
        out_word.RenderControl(htmlWriter);

        //输出 
        Response.Write(writer.ToString());
        Response.End();    }


其中out_word是一个div的id 我将div中的内容导出成word 现在想设置页边距让它变宽 office word2010中页边距有 普通,窄,适中,宽等,我想设置成窄的类型,求高手指点 谢谢
------解决方案--------------------
打开WORD模板,赋值到书签
------解决方案--------------------
可以规定一下response页面输出的格式
response.Clear();
            response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", HttpUtility.UrlEncode(Encoding.UTF8.GetBytes(fileName))));
            response.ContentType = "application/vnd.ms-excel";
            response.Charset = "GB2312";
            response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

            response.Write(string.Format(@"<html><head><meta http-equiv=Content-Type content=""text/html; charset=GB2312""><style>{0}</style></head><body>", GetStyle()));
            response.Write(content);
            response.Write("");
            response.Write("</body></html>");
            response.Flush();
            try