zoukankan      html  css  js  c++  java
  • 导出到word

             1. //服务器端rendercontrol生成word文档
                #region
                //HttpContext.Current.Response.Clear();
                //HttpContext.Current.Response.Charset = "UTF-8";
                //HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=导出文档.doc");
                //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                //HttpContext.Current.Response.ContentType = "applicaton/ms-word";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
                //Page.EnableViewState = false;
                //System.IO.StringWriter sw = new System.IO.StringWriter();
                //System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
                //this.renderexport.RenderControl(hw);
                //HttpContext.Current.Response.Write(sw.ToString());
                //HttpContext.Current.Response.End();

    2. 将word文档另存为html页面,然后将html中需要替换的内容改成$$,在aspx页面中将内容替换掉。后通过下面代码输出其中word参数为字符串

    Response.ContentEncoding = System.Text.Encoding.Default;
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename="  + "export.doc"); //这就是我失误的地方 attachment 写成了 inline
                Response.ContentType = "vnd.ms-excel/msword ";
                Response.Write(word);
                Response.Flush();
                Response.Close();

    3.通过js导出word,注意浏览器中安全内ActiveX要均设为启用,其中value为通过document.getElementById方法获得的对象

    function areaword(value) {
        var wd = new ActiveXObject("Word.Application");
        var doc = wd.Documents.Add("", 0, 1);
        var range = doc.Range(0, 1);
        var sel = document.body.createTextRange();
        sel.moveToElementText(value);
        sel.select();
        sel.execCommand("Copy");
        range.Paste();
        wd.Application.Visible = true;
        return false;
    }   

  • 相关阅读:
    Maven(二)Maven项目的创建(命令、myeclipse)及生命周期
    Maven(一)初识Maven
    MySQL(十一)之触发器
    MySQL(十)之视图
    MySQL(九)之数据表的查询详解(SELECT语法)二
    MySQL(九)之数据表的查询详解(SELECT语法)一
    关于oracle的锁表解决session marked for kill
    shell脚本清空redis库缓存
    Java 数组拷贝方法 System.arraycopy
    oracle 替换字符 replace
  • 原文地址:https://www.cnblogs.com/baozi/p/3200686.html
Copyright © 2011-2022 走看看