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;
    }   

  • 相关阅读:
    小程序配置安装
    微信小程序--录制音频,播放音频
    微信小程序报错.wxss无法找到
    linux 安装 elasticsearch
    Ubuntu 安装Logstash
    python 开发微信 自定义菜单
    微信 python搭建服务器
    vue 本地存储数据 sessionStorage
    luogu1742 最小圆覆盖
    luogu1501 [国家集训队]Tree II
  • 原文地址:https://www.cnblogs.com/baozi/p/3200686.html
Copyright © 2011-2022 走看看