精华内容
下载资源
问答
  • PowerDesigner导出word模版

    千次下载 热门讨论 2013-05-20 00:05:11
    PowerDesigner导出word通用模版,导出表清单和表列清单
  • html导出 word文档教程

    万次阅读 多人点赞 2017-10-19 13:24:47
    最近搞项目 需要用到导出word 文档,由于呢 他要显示word格式,我就 用word文档生成模板,现在 分享给大家。 这是我在网上找的 demo,按照 功能 不错大家可以看看 1、加入两个外部js FileSaver.js /* ...

    最近搞项目 需要用到导出word 文档,由于呢 他要显示word格式,我就 用word文档生成模板,现在 分享给大家。

    这是我在网上找的 demo,按照 功能 不错大家可以看看

    1、加入两个外部js

    FileSaver.js

    /* FileSaver.js
     * A saveAs() FileSaver implementation.
     * 1.3.2
     * 2016-06-16 18:25:19
     *
     * By Eli Grey, http://eligrey.com
     * License: MIT
     *   See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
     */
    
    /*global self */
    /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
    
    /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
    
    var saveAs = saveAs || (function(view) {
        "use strict";
        // IE <10 is explicitly unsupported
        if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
            return;
        }
        var
              doc = view.document
              // only get URL when necessary in case Blob.js hasn't overridden it yet
            , get_URL = function() {
                return view.URL || view.webkitURL || view;
            }
            , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
            , can_use_save_link = "download" in save_link
            , click = function(node) {
                var event = new MouseEvent("click");
                node.dispatchEvent(event);
            }
            , is_safari = /constructor/i.test(view.HTMLElement)
            , is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)
            , throw_outside = function(ex) {
                (view.setImmediate || view.setTimeout)(function() {
                    throw ex;
                }, 0);
            }
            , force_saveable_type = "application/octet-stream"
            // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
            , arbitrary_revoke_timeout = 1000 * 40 // in ms
            , revoke = function(file) {
                var revoker = function() {
                    if (typeof file === "string") { // file is an object URL
                        get_URL().revokeObjectURL(file);
                    } else { // file is a File
                        file.remove();
                    }
                };
                setTimeout(revoker, arbitrary_revoke_timeout);
            }
            , dispatch = function(filesaver, event_types, event) {
                event_types = [].concat(event_types);
                var i = event_types.length;
                while (i--) {
                    var listener = filesaver["on" + event_types[i]];
                    if (typeof listener === "function") {
                        try {
                            listener.call(filesaver, event || filesaver);
                        } catch (ex) {
                            throw_outside(ex);
                        }
                    }
                }
            }
            , auto_bom = function(blob) {
                // prepend BOM for UTF-8 XML and text/* types (including HTML)
                // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
                if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
                    return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
                }
                return blob;
            }
            , FileSaver = function(blob, name, no_auto_bom) {
                if (!no_auto_bom) {
                    blob = auto_bom(blob);
                }
                // First try a.download, then web filesystem, then object URLs
                var
                      filesaver = this
                    , type = blob.type
                    , force = type === force_saveable_type
                    , object_url
                    , dispatch_all = function() {
                        dispatch(filesaver, "writestart progress write writeend".split(" "));
                    }
                    // on any filesys errors revert to saving with object URLs
                    , fs_error = function() {
                        if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
                            // Safari doesn't allow downloading of blob urls
                            var reader = new FileReader();
                            reader.onloadend = function() {
                                var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
                                var popup = view.open(url, '_blank');
                                if(!popup) view.location.href = url;
                                url=undefined; // release reference before dispatching
                                filesaver.readyState = filesaver.DONE;
                                dispatch_all();
                            };
                            reader.readAsDataURL(blob);
                            filesaver.readyState = filesaver.INIT;
                            return;
                        }
                        // don't create more object URLs than needed
                        if (!object_url) {
                            object_url = get_URL().createObjectURL(blob);
                        }
                        if (force) {
                            view.location.href = object_url;
                        } else {
                            var opened = view.open(object_url, "_blank");
                            if (!opened) {
                                // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
                                view.location.href = object_url;
                            }
                        }
                        filesaver.readyState = filesaver.DONE;
                        dispatch_all();
                        revoke(object_url);
                    }
                ;
                filesaver.readyState = filesaver.INIT;
    
                if (can_use_save_link) {
                    object_url = get_URL().createObjectURL(blob);
                    setTimeout(function() {
                        save_link.href = object_url;
                        save_link.download = name;
                        click(save_link);
                        dispatch_all();
                        revoke(object_url);
                        filesaver.readyState = filesaver.DONE;
                    });
                    return;
                }
    
                fs_error();
            }
            , FS_proto = FileSaver.prototype
            , saveAs = function(blob, name, no_auto_bom) {
                return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
            }
        ;
        // IE 10+ (native saveAs)
        if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
            return function(blob, name, no_auto_bom) {
                name = name || blob.name || "download";
    
                if (!no_auto_bom) {
                    blob = auto_bom(blob);
                }
                return navigator.msSaveOrOpenBlob(blob, name);
            };
        }
    
        FS_proto.abort = function(){};
        FS_proto.readyState = FS_proto.INIT = 0;
        FS_proto.WRITING = 1;
        FS_proto.DONE = 2;
    
        FS_proto.error =
        FS_proto.onwritestart =
        FS_proto.onprogress =
        FS_proto.onwrite =
        FS_proto.onabort =
        FS_proto.onerror =
        FS_proto.onwriteend =
            null;
    
        return saveAs;
    }(
           typeof self !== "undefined" && self
        || typeof window !== "undefined" && window
        || this.content
    ));
    // `self` is undefined in Firefox for Android content script context
    // while `this` is nsIContentFrameMessageManager
    // with an attribute `content` that corresponds to the window
    
    if (typeof module !== "undefined" && module.exports) {
      module.exports.saveAs = saveAs;
    } else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
      define([], function() {
        return saveAs;
      });
    }

    2)jquery.wordexport.js

    if (typeof jQuery !== "undefined" && typeof saveAs !== "undefined") {
        (function($) {
            $.fn.wordExport = function(fileName) {
                fileName = typeof fileName !== 'undefined' ? fileName : "jQuery-Word-Export";
                var static = {
                    mhtml: {
                        top: "Mime-Version: 1.0\nContent-Base: " + location.href + "\nContent-Type: Multipart/related; boundary=\"NEXT.ITEM-BOUNDARY\";type=\"text/html\"\n\n--NEXT.ITEM-BOUNDARY\nContent-Type: text/html; charset=\"utf-8\"\nContent-Location: " + location.href + "\n\n<!DOCTYPE html>\n<html>\n_html_</html>",
                        head: "<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n<style>\n_styles_\n</style>\n</head>\n",
                        body: "<body>_body_</body>"
                    }
                };
                var options = {
                    maxWidth: 624
                };
                // Clone selected element before manipulating it
                var markup = $(this).clone();
    
                // Remove hidden elements from the output
                markup.each(function() {
                    var self = $(this);
                    if (self.is(':hidden'))
                        self.remove();
                });
    
                // Embed all images using Data URLs
                var images = Array();
                var img = markup.find('img');
                for (var i = 0; i < img.length; i++) {
                    // Calculate dimensions of output image
                    var w = Math.min(img[i].width, options.maxWidth);
                    var h = img[i].height * (w / img[i].width);
                    // Create canvas for converting image to data URL
                    var canvas = document.createElement("CANVAS");
                    canvas.width = w;
                    canvas.height = h;
                    // Draw image to canvas
                    var context = canvas.getContext('2d');
                    context.drawImage(img[i], 0, 0, w, h);
                    // Get data URL encoding of image
                    var uri = canvas.toDataURL("image/png");
                    $(img[i]).attr("src", img[i].src);
                    img[i].width = w;
                    img[i].height = h;
                    // Save encoded image to array
                    images[i] = {
                        type: uri.substring(uri.indexOf(":") + 1, uri.indexOf(";")),
                        encoding: uri.substring(uri.indexOf(";") + 1, uri.indexOf(",")),
                        location: $(img[i]).attr("src"),
                        data: uri.substring(uri.indexOf(",") + 1)
                    };
                }
    
                // Prepare bottom of mhtml file with image data
                var mhtmlBottom = "\n";
                for (var i = 0; i < images.length; i++) {
                    mhtmlBottom += "--NEXT.ITEM-BOUNDARY\n";
                    mhtmlBottom += "Content-Location: " + images[i].location + "\n";
                    mhtmlBottom += "Content-Type: " + images[i].type + "\n";
                    mhtmlBottom += "Content-Transfer-Encoding: " + images[i].encoding + "\n\n";
                    mhtmlBottom += images[i].data + "\n\n";
                }
                mhtmlBottom += "--NEXT.ITEM-BOUNDARY--";
    
                //TODO: load css from included stylesheet
                var styles = "";
    
                // Aggregate parts of the file together
                var fileContent = static.mhtml.top.replace("_html_", static.mhtml.head.replace("_styles_", styles) + static.mhtml.body.replace("_body_", markup.html())) + mhtmlBottom;
    
                // Create a Blob with the file contents
                var blob = new Blob([fileContent], {
                    type: "application/msword;charset=utf-8"
                });
                saveAs(blob, fileName + ".doc");
            };
        })(jQuery);
    } else {
        if (typeof jQuery === "undefined") {
            console.error("jQuery Word Export: missing dependency (jQuery)");
        }
        if (typeof saveAs === "undefined") {
            console.error("jQuery Word Export: missing dependency (FileSaver.js)");
        }
    }

    2、在页面加入一个div或者在body上面加入一个id,div和body必须包含要导出的部分注意要把导出的WORD模板放入此DIV里面,应网友而补更新, 步骤是自己在office word里面将写好的模型保存为html然后将其复制,当然样式也不能丢,得放进css样式里面,html呢就将其放到div里面

    <div id="export_word">
        <p>要导出的页面内容</p>
    </div>
    

    3、可以指定id内容导出(按钮名称exportWord())

     
    <a href="javascript:void(0)" class="btn btn-primary" onclick="exportWord()">导出</a>

    function exportWord(){
        $("#export_word").wordExport();
    }

    4、也可以在自己的js里面写入(具体按钮自己写入方法名称exportWord(),按钮的id="export_word")

    function exportWord(){
        $("#export_word").hide();
        $("html").wordExport();
        $("#export_word").show();
    }

    展开全文
  • 导出word.zip

    2021-02-06 15:54:55
    使用模板导出导出word
  • AsposeWord导出word表格,简单封装成了AsposeWordHelper,开发工具:vs2015
  • 在线导出word文件

    2018-04-13 12:41:08
    实现在线导出word文件。实现在线导出word文件。实现在线导出word文件。实现在线导出word文件。实现在线导出word文件。
  • Itext导出word

    2017-09-29 13:36:27
    Itext 导出word,可以导出富文本内容包括图片以及复杂的样式内容,可以导出表格,和图片等内容。
  • freemarker 导出word

    2017-08-10 17:46:02
    freemarker 导出word 的源码
  • poi 导出 word 导出excel

    2015-03-11 10:59:09
    亲测 poi 导出word 导出excel项目 导入 myeclipse 可运行
  • itext导出word导出

    2013-08-08 12:29:11
    itext 导出word 全部 用法,归纳总结了常用例子好好学习吧
  • java导出Word

    2014-11-15 18:52:22
    java实现导出Word,可以导出图片到Word,
  • 导出word工具.rar

    2021-02-23 15:39:04
    导出word工具.rar
  • freemarker导出word

    2015-06-12 10:36:18
    利用freemarker模板导出word
  • Java导出word

    2018-09-29 10:58:37
    Java用freemarker导出word.
  • PHP导出WORD

    2013-09-05 09:25:40
    PHP导出WORD
  • 自定义导出word模板,模板包含表清单、索引清单、表列清单
  • FreeMarker导出word

    2016-08-01 09:58:04
    FreeMarker导出word
  • java导出word之freemarker导出程序 ,java工程,能正常执行,很好的入门实例
  • jquery页面导出word

    2018-05-22 11:08:54
    jquery插件实现页面导出word。可以导出文本,表格,图片等类型的数据到word,同时保留样式,还有word-icon展示。
  • C#导出Word

    2015-08-17 23:35:35
    导入导出Excel见多了,现在奉上导出Word的代码片段,代码简单易懂,注释明了。
  • jquery插件导出WORD

    2017-11-21 17:25:27
    利用插件导出WORD所需要的js,这个是所需要导出word用的前端代码:http://blog.csdn.net/weixin_38959210/article/details/78594746
  • 导出Word (js方式)

    2018-01-12 10:59:03
    导出Word (js方式)导出Word (js方式)导出Word (js方式)导出Word (js方式)
  • C#导出word

    2017-09-05 15:05:18
    .NET 实现,导出word功能。 string outputFile = "测试-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".docx"; EwfDocumentGenerator.GenerateFile("通知书.docx", outputFile, data, new ...
  • PowerDesigner导出word模板.rar
  • POI导出word

    千次阅读 2019-01-03 13:45:05
    poi导出word 最近有一个项目需要用做导出word的功能,刚开始用的是poi,开始写的时候才发现poi对于word的支持真的是少的可怜,还是推荐大家用xml或者别的来做导出word,本次功能分两篇博客展现如果用需要用poi的...

    poi导出word

    最近有一个项目需要用做导出word的功能,刚开始用的是poi,开始写的时候才发现poi对于word的支持真的是少的可怜,还是推荐大家用xml或者别的来做导出word,本次功能分两篇博客展现如果用需要用poi的可以看看这篇博客,欢迎补充。

    1. 替换word表格参数
    2. 动态生成行

    替换word模板参数 

    根据word模板导出word

    public class WordUtil {
     /**
         * 替换所有段落中的标记
         *
         * @param xwpfParagraphList
         * @param params
         */
        public static void replaceInAllParagraphs(List<XWPFParagraph> xwpfParagraphList, Map<String, String> params) {
            for (XWPFParagraph paragraph : xwpfParagraphList) {
                if (paragraph.getText() == null || paragraph.getText().equals("")) continue;
                for (String key : params.keySet()) {
                    if (paragraph.getText().contains(key)) {
                        replaceInParagraph(paragraph, key, params.get(key));
                    }
                }
            }
        }
    
        /**
         * 替换段落中的字符串
         *
         * @param xwpfParagraph
         * @param oldString
         * @param newString
         */
        public static void replaceInParagraph(XWPFParagraph xwpfParagraph, String oldString, String newString) {
            Map<String, Integer> pos_map = findSubRunPosInParagraph(xwpfParagraph, oldString);
            if (pos_map != null) {
                List<XWPFRun> runs = xwpfParagraph.getRuns();
                XWPFRun modelRun = runs.get(pos_map.get("end_pos"));
                XWPFRun xwpfRun = xwpfParagraph.insertNewRun(pos_map.get("end_pos") + 1);
                xwpfRun.setText(newString);
                if (modelRun.getFontSize() != -1)
                    xwpfRun.setFontSize(modelRun.getFontSize());//默认值是五号字体,但五号字体getFontSize()时,返回-1
                xwpfRun.setFontFamily(modelRun.getFontFamily());
                for (int i = pos_map.get("end_pos"); i >= pos_map.get("start_pos"); i--) {
                    xwpfParagraph.removeRun(i);
                }
            }
        }
    
        /**
         * 找到段落中子串的起始XWPFRun下标和终止XWPFRun的下标
         *
         * @param xwpfParagraph
         * @param substring
         * @return
         */
        public static Map<String, Integer> findSubRunPosInParagraph(XWPFParagraph xwpfParagraph, String substring) {
            List<XWPFRun> runs = xwpfParagraph.getRuns();
            int start_pos = 0;
            int end_pos = 0;
            String subtemp = "";
            for (int i = 0; i < runs.size(); i++) {
                subtemp = "";
                start_pos = i;
                for (int j = i; j < runs.size(); j++) {
                    if (runs.get(j).getText(runs.get(j).getTextPosition()) == null) continue;
                    subtemp += runs.get(j).getText(runs.get(j).getTextPosition());
                    if (subtemp.equals(substring)) {
                        end_pos = j;
                        Map<String, Integer> map = new HashMap<>();
                        map.put("start_pos", start_pos);
                        map.put("end_pos", end_pos);
                        return map;
                    }
                }
            }
            return null;
        }
    
        /**
         * 替换所有的表格
         *
         * @param xwpfTableList
         * @param params
         */
        public static void replaceInTables(List<XWPFTable> xwpfTableList, Map<String, String> params) {
            for (XWPFTable table : xwpfTableList) {
                replaceInTable(table, params);
            }
        }
    
        /**
         * 替换一个表格中的所有行
         *
         * @param xwpfTable
         * @param params
         */
        public static void replaceInTable(XWPFTable xwpfTable, Map<String, String> params) {
            List<XWPFTableRow> rows = xwpfTable.getRows();
            replaceInRows(rows, params);
        }
    
        /**
         * 替换表格中的一行
         *
         * @param rows
         * @param params
         */
        public static void replaceInRows(List<XWPFTableRow> rows, Map<String, String> params) {
            for (int i = 0; i < rows.size(); i++) {
                XWPFTableRow row = rows.get(i);
                replaceInCells(row.getTableCells(), params);
            }
        }
    
        /**
         * 替换一行中所有的单元格
         *
         * @param xwpfTableCellList
         * @param params
         */
        public static void replaceInCells(List<XWPFTableCell> xwpfTableCellList, Map<String, String> params) {
            for (XWPFTableCell cell : xwpfTableCellList) {
                replaceInCell(cell, params);
            }
        }
    
        /**
         * 替换表格中每一行中的每一个单元格中的所有段落
         *
         * @param cell
         * @param params
         */
        public static void replaceInCell(XWPFTableCell cell, Map<String, String> params) {
            List<XWPFParagraph> cellParagraphs = cell.getParagraphs();
            replaceInAllParagraphs(cellParagraphs, params);
         }
        }

    下面是调用方法
    因为map泛型规定了String,所以非String类型的参数都要用""串接起来

    public static void main(String[] args) {
            Map<String, String> params = new HashMap<>();
            params.put("${name}", "请假");
            params.put("${user}", "邹某");
            params.put("${time}", "" + new SimpleDateFormat("yyyy-MM-dd hh:mm").format(new Date()) + "");
            params.put("${type}", "产假");
            params.put("${project}", "金融");
            params.put("${startTime}", "2018-12-05 12:00");
            params.put("${endTime}", "2018-12-05 12:00");
            params.put("${dept}", "开发部");
            params.put("${numDay}", "1");
            params.put("${remark}", "不想上班");
            String filepath = "E:\\test.docx";
            String destpath = "E:\\test3.docx";
            WordUtil wordUtil = new WordUtil();
          WordUtil wordUtil = new WordUtil();
            try {
                OPCPackage pack = POIXMLDocument.openPackage(filepath);//读取模板文件
                XWPFDocument document = new XWPFDocument(pack);//创建word文件并将模板导入
                //对段落中的标记进行替换
            	List<XWPFParagraph> parasList = xwpfDocument.getParagraphs();
            	replaceInAllParagraphs(parasList, map);
                //表格标记替换
                List<XWPFTable> tables = document.getTables();
                wordUtil.replaceInTables(tables, params);
                FileOutputStream  outStream = new FileOutputStream(destpath);
                document.write(outStream);
                outStream.flush();
                outStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    å¨è¿éæå¥å¾çæè¿°

    å¨è¿éæå¥å¾çæè¿°

    以上就是poi替换word模板参数的所有内容,欢迎补充

     

    展开全文
  • C# MVC开发的根据word模板导出word的功能,功能很完善,绝对可用的。环境是VS2013,MVC4
  • java freemark导出word

    2017-07-25 16:25:50
    java freemark导出word,附带说明文档
  • itext 导出 word 实例

    2017-07-27 16:11:22
    用到的一个导出word表格的实例
  • itext导出word整理

    2017-09-16 16:50:50
    itext导出word整理

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 66,564
精华内容 26,625
关键字:

导出word