Ziv-Barber / officegen

Standalone Office Open XML files (Microsoft Office 2007 and later) generator for Word (docx), PowerPoint (pptx) and Excell (xlsx) in javascript. The output is a stream.
MIT License
2.65k stars 471 forks source link

Word Document is corrupt #276

Closed rosman21 closed 5 years ago

rosman21 commented 5 years ago

Any time I attempt to open a word document, I get a error showing this screen shot 2018-10-11 at 3 28 17 pm

works on my local server but not in my production enviorment. Not sure what the issue is.

Here is my code and version

Version: "officegen": "^0.4.5",

Code:

requestify.get(url).then(function(response) {
            var data = JSON.parse(response.body);
            var docx = officegen ( 'docx' );
            docx.on ( 'error', function ( err ) {
                console.log ( err );
            });
            var pObj = docx.createP ();
            pObj.addText ( "Results" );
             pObj.addLineBreak ();
            for(var i = 0; i < data.hits.hits.length; i++){
                var currObj = data.hits.hits[i]._source;
                var http ="http://T.T.T.com/"+currObj.meeting_url;

                pObj.addText ( "Topic: " + T , {link: http, color: '4284f5' } );
                pObj.addLineBreak ();
                pObj.addLineBreak ();
                pObj.addText ( "Meeting: " + E  );
                pObj.addLineBreak ();
                pObj.addLineBreak ();
                pObj.addText ( "F: " + R );
                pObj.addLineBreak ();
                pObj.addLineBreak ();
                pObj.addText ( "Q: " + T );
                pObj.addLineBreak ();
                pObj.addLineBreak ();
                pObj.addText ( "Discussio: " + H );
                pObj.addLineBreak ();
                pObj.addLineBreak ();
                pObj.addText ( "Action : " + J  );
                pObj.addLineBreak ();
                pObj.addLineBreak ();
                pObj.addText ( "V: " + K  );
                pObj.addLineBreak ();
                pObj.addLineBreak ();
                pObj.addText ( "A " + M );
                pObj.addHorizontalLine ();
            }
            res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.documentml.document");
            res.setHeader("Content-Disposition", "attachment; filename=Results.docx");
            docx.generate(res);
            console.log("Generated");
        });
Ziv-Barber commented 5 years ago

docx.generate(res);

This function is working async. You can find a working example in /examples/pptx_server.js