{"size": 1871, "ext": "js", "max_stars_repo_path": "node/office/index.js", "max_stars_repo_name": "821484451/study", "max_stars_repo_stars_event_min_datetime": "2019-06-05T06:17:24.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-05T06:17:24.000Z", "max_issues_repo_path": "node/office/index.js", "max_issues_repo_name": "821484451/study", "max_issues_repo_issues_event_min_datetime": "2020-09-05T22:33:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T18:53:40.000Z", "max_forks_repo_path": "node/office/index.js", "max_forks_repo_name": "821484451/study", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 28, "max_forks_count": null, "avg_line_length": 27.9253731343, "max_line_length": 99, "alphanum_fraction": 0.6119722074}
var  officegen  = require('officegen');
var fs = require('fs');
var docx = officegen({'type': 'docx'});
var pptx = officegen({'type': 'pptx'});
var xlsx = officegen({'type': 'xlsx'});
var http = require("http");
var path = require('path');

docx.on('finalize', function (written) {
  console.log(written);
});
docx.on('error', function (error) {
  console.log(error);
});
var pObj = docx.createP ();
pObj.options.align = 'center';
pObj.addText ( 'Simple' );

pObj.addText ( ' with color', { color: '000088' } );

pObj.addText ( ' and back color.', { color: '00ffff', back: '000088' } );

pObj.addText ( 'Bold + underline', { bold: true, underline: true } );

pObj.addText ( 'Fonts face only.', { font_face: 'Arial' } );

pObj.addText ( ' Fonts face and size. ', { font_face: 'Arial', font_size: 40 } );

pObj.addText ( 'External link', { link: 'https://github.com' } );


pObj.addText ( 'Internal link', { hyperlink: 'myBookmark' } );
// 添加图片
console.log(__dirname)
console.log(path.resolve(__dirname, './myFile.png'));
pObj.addImage (path.resolve(__dirname, './myFile.png'),{ cx: 300, cy: 200 });
pObj.startBookmark ( 'myBookmark' );
pObj.endBookmark ();


var out = fs.createWriteStream ( 'out.docx' );

docx.generate ( out );
out.on ( 'close', function () {
  console.log ( 'Finished to create the PPTX file!' );
});

// http.createServer ( function ( request, response ) {
//   response.writeHead ( 200, {
//     "Content-Type": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
//     'Content-disposition': 'attachment; filename=surprise.pptx'
//     });

//   var pptx = officegen ( 'pptx' );

//   pptx.on ( 'finalize', function ( written ) {
//       // ...
//       });

//   pptx.on ( 'error', function ( err ) {
//       // ...
//       });

//   // ... (fill pptx with data)

//   pptx.generate ( response );
// }).listen ( 3000 );