Nodejs Export Word

Source: Internet
Author: User

  • Nodejs Export Word This is very distressing, but also studied for half a day, but in a colleague's struggle and Baidu this powerful tool
    Still barely finished. Here is Officegen this plug-in, this plugin is still very powerful, you can export Excel,
    Ppt,word;
  • First introduce Officegen:
    var Officegen = require (' Officegen ');//after it is used in the code:
    Router.get ('/exportword ', function (req, res) {
    try {
    var docx = Officegen (' docx ');//Here This is used in the method, because read Baidu on an article, put in the beginning
    Global, this causes the exported data to repeat, this suffering for a long time, or a colleague to force
    var meet_name = Req.query.meet_name;
    Query meeting information through meeting name, topic information
    Service.getmeetinfo (1, 100000, meet_name, function (meet) {
    if (Meet.rows[0].t_begin = = "" | | Meet.rows[0].address = = "") {
    Res.send ("0");
    } else {
    /
    Determine if a file exists
    /
    var filedir = './public/uploadfile/temporaryfile/';
    Fs.ensuredir (Filedir, function (err) {
    });
    Fs.exists (Filedir + meet_name + ' _ meeting notice. docx ', function (r) {
    if (r) {
    Fs.unlinksync (Filedir + meet_name + ' _ meeting notice. docx ', function (err) {
    if (err) throw err;
    })
    }
    /
    Get data, process data
    /
    Issueservice.getissueinfo (1, 100000, meet_name, function (result) {
    var str = ';
    for (var i = 0; i < result.rows.length; i++) {
    str + = result.rows[i].report_dept + ",";//Attendance sections
    if (result.rows[i].involv_dept! = "does not involve") {
    str + = result.rows[i].involv_dept + ",";//related departments
    }
    }

                var strarray = Str.split (",");            var report = [];  Go to Heavy for (var k = 0; k < strarray.length; k++) {if (strarray[k]! = "Quality Management room" && strarray[k]! = "Operations Management Room" && strarray[k]! = "Audit Funding chamber") {if (Strarray.indexof (strarray[k]) = = k) Report.push (Strar            Ray[k]);            }} var ss = Report.tostring (). Split (",");            var strs = '; for (var i = 0; i < ss.length; i++) {if (ss[i] = = "| | ss[i] = = NULL | | typeof (Ss[i]) = = Undefine                            d) {Ss.splice (I, 1);                    i = i-1;                            }} for (var i = 0; i < ss.length; i++) {if (i = = ss.length-1) {                            STRs + = Ss[i].split (","). ToString () + ";";                    Break                    } STRs + = Ss[i] + ","; } var Qty                    if (STRs = = "") {st = ";";                    } else {st = ",";                    }/* Line break */var POBJ = Docx.createp ();                    Pobj.addtext (");                    var pObj = Docx.createp ();                    Pobj.addtext (");                    var pObj = Docx.createp ();                    Pobj.addtext (");                    var pObj = Docx.createp ();                    Pobj.addtext (");  /* Provide line break *///var PObj4 = Docx.createp ({align: ' center '});//Create Line                    Set Center//pobj4.addtext (meet.rows[0].meet_name + ' meeting notifications ', {bold:true, font_face: ' Arial ', font_size:18});                    Add text set font style bold size//write data var pObj = Docx.createp ();           Pobj.addtext (' Conference name: ', {bold:true});         Pobj.addtext (meet.rows[0].meet_name) var pObj = Docx.createp ();                    Pobj.addtext (' Meeting time: ', {bold:true});//Set Font color Pobj.addtext (meet.rows[0].t_begin);                    var pObj = Docx.createp ();                    Pobj.addtext (' Meeting place: ', {bold:true});                    Pobj.addtext (meet.rows[0].address);                    var pObj = Docx.createp ();                    Pobj.addtext (' Participating departments: ', {bold:true});                    Pobj.addtext (' Quality control room, operation and maintenance management room, Audit capital control room ' + st + STRs);                    var pObj = Docx.createp ();                    Pobj.addtext (' The contents of this meeting, please see the summary table below, has now collected the topic "');                    Pobj.addtext ("" + Result.total + "", {color: ' FF0000 '}); Pobj.addtext (' "A. Please prepare the issue report department and the participating departments in advance.                    ‘); var out = Fs.createwritestream (Filedir + meet_name + ' _ meeting notification. docx ');//File Write Docx.generate (out);//Server Generation W                        Ord Out.on (' Error ', function (err) {    Console.log (ERR);                    }); Out.on (' Finish ', function () {Console.log ("write complete.                            "); /* Set 5 minutes to delete the generated word, avoiding server resources */SetTimeout (() = {try {fs.access ('./public/upload  file/temporaryfile/' + Meet_name + ' _ meeting notice. docx ', Fs.constants.F_OK, (err) =                                                            {if (!err) { Fs.unlinksync ('./public/uploadfile/temporaryfile/' + meet_n                                                    Ame + ' _ meeting notice. docx ');                                    }                                            }); } catch (e) {consolE.error (e);                            }}, 5 * 60 * 1000);                    Returns the Res.send ('/uploadfile/temporaryfile/' + Meet_name + ' _ meeting notification. docx ') generated by word in the server. });

    Finally: the page directly through the path to download word, here is attached to the page Ajax after the successful code;
    Success:function (R) {
    $.messager.progress (' close ');
    if (r = = "Err") {
    Msgerror (' Export failed!, please retry later ');
    }
    if (r = = "0") {
    Msgerror ("Please complete and confirm the basic information of the Meeting");
    } else {
    Get the current URL, such as: http://localhost:8080/imgs/doc/abc.jsp
    var curwwwpath = Window.document.location.href;
    Gets the directory after the host address, such as: imgs/doc/abc.jsp
    var pathName = Window.document.location.pathname;
    var pos = curwwwpath.indexof (pathName);
    Get host address, such as: http://localhost:8080
    var localhostpaht = curwwwpath.substring (0, POS);
    Location.href = Localhostpaht + R;
    }
    },

  • Nodejs Export Word

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.