Giter VIP home page Giter VIP logo

officegen's Introduction

officegen

Creating Office Open XML files (Word, Excel and Powerpoint) for Microsoft Office 2007 and later without external tools, just pure Javascript. officegen should work on any environment that supports Node.js including Linux, OSX and Windows. officegen also supporting PowerPoint native charts objects with embedded data.

npm version dependencies devDependencies Build Status Join the chat at https://gitter.im/officegen/Lobby Backers on Open Collective Sponsors on Open Collective

Officegen logo Microsoft Office logo

Contributors:

This project exists thanks to all the people who contribute.

Getting Started:

Microsoft Powerpoint logo Microsoft Word logo Microsoft Excel logo

Officegen features overview:

  • Generating Microsoft PowerPoint document (.pptx file):
    • Create PowerPoint document with one or more slides.
    • Support both PPT and PPS.
    • Can create native charts.
    • Add text blocks.
    • Add images.
    • Can declare fonts, alignment, colors and background.
    • You can rotate objects.
    • Support shapes: Ellipse, Rectangle, Line, Arrows, etc.
    • Support hidden slides.
    • Support automatic fields like date, time and current slide number.
    • Support speaker notes.
    • Support slide layouts.
  • Generating Microsoft Word document (.docx file):
    • Create Word document.
    • You can add one or more paragraphs to the document and you can set the fonts, colors, alignment, etc.
    • You can add images.
    • Support header and footer.
    • Support bookmarks and hyperlinks.
  • Generating Microsoft Excel document (.xlsx file):
    • Create Excel document with one or more sheets. Supporting cells with either numbers or strings.

Installation:

$ npm install officegen

Microsoft PowerPoint basic usage example:

const officegen = require('officegen')
const fs = require('fs')

// Create an empty PowerPoint object:
let pptx = officegen('pptx')

// Let's add a title slide:

let slide = pptx.makeTitleSlide('Officegen', 'Example to a PowerPoint document')

// Pie chart slide example:

slide = pptx.makeNewSlide()
slide.name = 'Pie Chart slide'
slide.back = 'ffff00'
slide.addChart(
  {
    title: 'My production',
    renderType: 'pie',
    data:
	[
      {
        name: 'Oil',
        labels: ['Czech Republic', 'Ireland', 'Germany', 'Australia', 'Austria', 'UK', 'Belgium'],
        values: [301, 201, 165, 139, 128,  99, 60],
        colors: ['ff0000', '00ff00', '0000ff', 'ffff00', 'ff00ff', '00ffff', '000000']
      }
    ]
  }
)

// Let's generate the PowerPoint document into a file:

return new Promise((resolve, reject) => {
  let out = fs.createWriteStream('example.pptx')

  // This one catch only the officegen errors:
  pptx.on('error', function(err) {
    reject(err)
  })

  // Catch fs errors:
  out.on('error', function(err) {
    reject(err)
  })

  // End event after creating the PowerPoint file:
  out.on('close', function() {
    resolve()
  })

  // This async method is working like a pipe - it'll generate the pptx data and put it into the output stream:
  pptx.generate(out)
})

Since that officegen is using node.js events you can also create a document directly into a http respons stream:

const officegen = require('officegen')
const http = require('http')

/**
 * This is a simple web server that response with a PowerPoint document.
 */
http.createServer(function(req, res) {
  // We'll send a generated on the fly PowerPoint document without using files:
  if (req.url == '/') {
    // Create an empty PowerPoint object:
    let pptx = officegen('pptx')

    // Let's create a new slide:
    var slide = pptx.makeNewSlide()

    slide.name = 'Hello World'

    // Change the background color:
    slide.back = '000000'

    // Declare the default color to use on this slide:
    slide.color = 'ffffff'

    // Basic way to add text string:
    slide.addText('Created on the fly using a http server!')

    //
    // Let's generate the PowerPoint document directly into the response stream:
    //

    response.writeHead(200, {
      'Content-Type':
        'application/vnd.openxmlformats-officedocument.presentationml.presentation',
      'Content-disposition': 'attachment filename=out.pptx'
    })

	// Content types related to Office documents:
    // .xlsx   application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    // .xltx   application/vnd.openxmlformats-officedocument.spreadsheetml.template
    // .potx   application/vnd.openxmlformats-officedocument.presentationml.template
    // .ppsx   application/vnd.openxmlformats-officedocument.presentationml.slideshow
    // .pptx   application/vnd.openxmlformats-officedocument.presentationml.presentation
    // .sldx   application/vnd.openxmlformats-officedocument.presentationml.slide
    // .docx   application/vnd.openxmlformats-officedocument.wordprocessingml.document
    // .dotx   application/vnd.openxmlformats-officedocument.wordprocessingml.template
    // .xlam   application/vnd.ms-excel.addin.macroEnabled.12
    // .xlsb   application/vnd.ms-excel.sheet.binary.macroEnabled.12

    // This one catch only the officegen errors:
    pptx.on('error', function(err) {
      res.end(err)
    })

    // Catch response errors:
    res.on('error', function(err) {
      res.end(err)
    })

    // End event after sending the PowerPoint data:
    res.on('finish', function() {
      res.end()
    })

    // This async method is working like a pipe - it'll generate the pptx data and pass it directly into the output stream:
    pptx.generate(res)
  } else {
    res.end('Invalid Request!')
  } // Endif.
}).listen(3000)

Where to go from here?

Microsoft Word basic usage example:

const officegen = require('officegen')
const fs = require('fs')

// Create an empty Word object:
let docx = officegen('docx')

// Officegen calling this function after finishing to generate the docx document:
docx.on('finalize', function(written) {
  console.log(
    'Finish to create a Microsoft Word document.'
  )
})

// Officegen calling this function to report errors:
docx.on('error', function(err) {
  console.log(err)
})

// Create a new paragraph:
let pObj = docx.createP()

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

pObj = docx.createP()

pObj.addText('Since ')
pObj.addText('officegen 0.2.12', {
  back: '00ffff',
  shdType: 'pct12',
  shdColor: 'ff0000'
}) // Use pattern in the background.
pObj.addText(' you can do ')
pObj.addText('more cool ', { highlight: true }) // Highlight!
pObj.addText('stuff!', { highlight: 'darkGreen' }) // Different highlight color.

pObj = docx.createP()

pObj.addText('Even add ')
pObj.addText('external link', { link: 'https://github.com' })
pObj.addText('!')

pObj = docx.createP()

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

pObj = docx.createP({ align: 'center' })

pObj.addText('Center this text', {
  border: 'dotted',
  borderSize: 12,
  borderColor: '88CCFF'
})

pObj = docx.createP()
pObj.options.align = 'right'

pObj.addText('Align this text to the right.')

pObj = docx.createP()

pObj.addText('Those two lines are in the same paragraph,')
pObj.addLineBreak()
pObj.addText('but they are separated by a line break.')

docx.putPageBreak()

pObj = docx.createP()

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

docx.putPageBreak()

pObj = docx.createP()

// We can even add images:
pObj.addImage('some-image.png')

// Let's generate the Word document into a file:

let out = fs.createWriteStream('example.docx')

out.on('error', function(err) {
  console.log(err)
})

// Async call to generate the output file:
docx.generate(out)

Where to go from here?

Microsoft Excel basic usage example:

const officegen = require('officegen')
const fs = require('fs')

// Create an empty Excel object:
let xlsx = officegen('xlsx')

// Officegen calling this function after finishing to generate the xlsx document:
xlsx.on('finalize', function(written) {
  console.log(
    'Finish to create a Microsoft Excel document.'
  )
})

// Officegen calling this function to report errors:
xlsx.on('error', function(err) {
  console.log(err)
})

let sheet = xlsx.makeNewSheet()
sheet.name = 'Officegen Excel'

// Add data using setCell:

sheet.setCell('E7', 42)
sheet.setCell('I1', -3)
sheet.setCell('I2', 3.141592653589)
sheet.setCell('G102', 'Hello World!')

// The direct option - two-dimensional array:

sheet.data[0] = []
sheet.data[0][0] = 1
sheet.data[1] = []
sheet.data[1][3] = 'some'
sheet.data[1][4] = 'data'
sheet.data[1][5] = 'goes'
sheet.data[1][6] = 'here'
sheet.data[2] = []
sheet.data[2][5] = 'more text'
sheet.data[2][6] = 900
sheet.data[6] = []
sheet.data[6][2] = 1972

// Let's generate the Excel document into a file:

let out = fs.createWriteStream('example.xlsx')

out.on('error', function(err) {
  console.log(err)
})

// Async call to generate the output file:
xlsx.generate(out)

Where to go from here?

Support:

Examples:

  • make_pptx.js - Example how to create PowerPoint 2007 presentation and save it into file.
  • make_xlsx.js - Example how to create Excel 2007 sheet and save it into file.
  • make_docx.js - Example how to create Word 2007 document and save it into file.
  • pptx_server.js - Example HTTP server that generating a PowerPoint file with your name without using files on the server side.

The official officegen Google Group:

officegen Google Group

The officegen Slack team:

Slack

Plans for the next release:

Trello

☕ The source code:

The project structure:

  • office/index.js - The main file.
  • office/lib/ - All the sources should be here.
    • basicgen.js - The generic engine to build many type of document files. This module providing the basicgen plugins interface for all the document generator. Any document generator MUST use this plugins API.
    • docplug.js - The document generator plugins interface - optional engine to create plugins API for each document generator.
    • msofficegen.js - A template basicgen plugin to extend the default basicgen module with the common Microsoft Office stuff. All the Microsoft Office based document generators in this project are using this template plugin.
    • genpptx.js - A document generator (basicgen plugin) to create a PPTX/PPSX document.
    • genxlsx.js - A document generator (basicgen plugin) to create a XLSX document.
    • gendocx.js - A document generator (basicgen plugin) to create a DOCX document.
    • pptxplg-*.js - docplug based plugins for genpptx.js ONLY to implement Powerpoint based features.
    • docxplg-*.js - docplug based plugins for genpptx.js ONLY to implement Word based features.
    • xlsxplg-*.js - docplug based plugins for genpptx.js ONLY to implement Excel based features.
  • officegen/test/ - All the unit tests.
  • Gruntfile.js - Grunt scripts.

Code documentations:

To create the jsdoc documentation:

grunt jsdoc

External dependencies:

This project is using the following awesome libraries/utilities/services:

  • archiver
  • jszip
  • lodash
  • xmlbuilder

How to add new features:

The easiest way to add new features is by using the officegen internal plugins system.

Credit:

  • Created by Ziv Barber in 2013.
  • For creating zip streams i'm using 'archiver' by cmilhench, dbrockman, paulj originally inspired by Antoine van Wel's zipstream.

Contributors:

This project exists thanks to all the people who contribute.

Backers:

Thank you to all our backers! 🙏 [Become a backer]

Sponsors:

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

officegen's People

Contributors

afortune avatar alextitanium avatar apsavin avatar aug2uag avatar benvd avatar bkylerussell avatar cgarethc avatar chinaqstar avatar colinjeanne avatar craigege avatar cxn-astracz avatar ericr-fw avatar grotaar avatar holm avatar humoran avatar japneet121 avatar jmetric avatar jwerre avatar karanpreettoor avatar keithmo avatar lixuanxian avatar magicienap avatar njcaruso avatar obscure-web avatar pdesantis avatar pietersv avatar qndrey avatar siddiqaa avatar vlampreia avatar ziv-barber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

officegen's Issues

missing requires statement in genpptx.js

Just hit this, in genpptx.js, line 889.

node_modules/officegen/lib/genpptx.js:889
                    var image_ext = path.extname ( image_path );
                                    ^
ReferenceError: path is not defined

I hit this by trying to insert a pdf file just to see what would happen. is it possible to stick a pdf directly into an pptx document? or does it need to be converted to emf or similar first?

Cool library, thanks for sharing it.

Documentation for available object properties missing.

It would be great to have a comprehensive list (or a link to an outside resource) for a list of available object properties. For example, working on pptx I was unable to find all available properties of the slide.addShape() method such as 'ellipse' or 'shape: "roundRect"' or how to draw a border. Thank you!

Documentation does not cover bodyProp options (i.e. vertical text alignment)

Please see https://github.com/Ziv-Barber/officegen/blob/master/lib/genpptx.js#L635-L678

Corresponding example:

function addSlides(lyrics) {
  var slides = lyrics.split('\n\n');
  console.log(slides.length + ' slides to generate');
  console.log(slides);

  for (var i in slides) {

    var lyrics = slides[i].split('\n').join('\r'); // Microsoft :/
    var lines = lyrics.split('\r').length;

    slide = pptx.makeNewSlide();
    slide.back = { type: 'solid', color: 'ffffff' };

    pObj = slide.addText(lyrics, {
      x: 0,
      y: 0,
      cx: '100%',
      cy: '100%',
      fill: 'ffffff',
      font_size: fontSize,
      align: 'ctr',
      color: {
        type: 'solid',
        color: '000000'
      },

      bodyProp: {
        anchor: 'ctr', // vertical align text
      },
    });

    pObj.options.align = 'center';
  }
}

Returning doc,docx files's proprieties like number of pages

I want to know if it's possible to be made with officegen or do I need something else. I want to get all files from a folders and return how many pages has each document with names and everything. I need an quick answer so anything will do . Thank you for the support.

addImage() for docx?

Hey, first off, this is a nice module!

I was almost able to use it for a current project, but your docx generation doesn't support inserting images into a docx file..

Is it a feature you will eventually get to? I see that the pptx generation supports it, so I thought I'd ask...

XLSX with cell format

Dear Sir,

I'm interesting to this tool.
Do you have any plan to add "Cell formatting" function for XLSX file?

Best regards,

Officegen 0.2.7 never finalizes in Node 0.8

OfficeGen prompts the user to start downloading the file as soon as docx.generate(res) is hit, however, it never finishes creating the file. In fact, it never even hits the callback of the finalize event (as shown below). Which makes me wonder... why does OfficeGen prompt the user before the file is built? And can we circumvent that by not sending anything to the user until the file is built?

var docx = officegen('docx');
// Here I call docx.createP().addText("foo bar") about 300 times
docx.on ( 'finalize', function () {
            console.log('This console log is never being written out.');
});
docx.on ( 'error', function ( err ) {    
            console.log ( err );
});
docx.generate(res);

Support for italicized text in pptx files

sample options:

slide.addText ( 'Boom!!!', {
    y: 250, x: 10, cx: '70%', 
    font_face: 'Wide Latin', font_size: 54, 
    color: 'cc0000', bold: true, underline: true, italic: true } );

Creating charts requires Java

I kept getting mysterious errors trying to generate charts with the new addChart() command. After digging into it for a while I discovered it was because I didn't have Java installed. This is because line 865 of lib/msexcel- builder runs the jar command via shell/exec. If jar is not an available command then you get an ENOENT error because it never creates sample1.xlsx and thus can't read the file.

This is either an unnecessary dependency, or it's a documentation issue. I wasn't sure which so I didn't make a pull request and instead am filing this bug. Anyway, thanks for an overall great library!

Edit text in a slide

Can we have the option of editing text in a slide?

And centering text is not working as expected.

Set Cell Background in XLSX

How do I set the background of a cell in an xlsx document? If this isn't possible, do you know what I should look at to begin implementing that. I'd be happy to submit a pull request if you like.

support streams or buffers

Would it be possible to extend support in slide.addImage() and pptx.generate() to simplify generating slidedecks on a server from in-memory data?

Now what I do is:

  • given a base64 image, I remove the metadata (data:image/png;base64,), then convert it to a Buffer, save it as a file using node-temp, then pass that file to slide.addImage()
  • given the assembled slidedeck, I create a tmp file to generate the pptx, then read it to a buffer to serve in an express middleware

Not sure if streams or buffers would be better here, I guess either one is fine as long as I don't need to bother with temp files.

Read Office files?

I realize this is a bit of a stretch from this library, but I'm looking for ways to read Office files with JavaScript (server or client-side). Any plans to add that here, or suggestions on where to look?

Creating bullet lists

The createListOfDots and CreateListOfNumbers doesn't really do anything for me. I assume it's supposed to make bullet-point formatting, but even when I create the sample doc, it just appears as new lines (no bullets or numbers). Is this a well-known problem? Is there a different way to create bullet points?

Attached is the bottom of the sample doc. Is that how it's supposed to look?
screenshot from 2014-11-03 13 09 10

support for tabstops or tables docx

There is no way to add tables / configure tabstops in docx files. This would be useful when trying to layout content in a tabular/presentable manner.

Would this be possible to add into the officegen API?

disable/override setting Author, Company document properties

officegen currently sets these two document properties to "officegen". I'd like to not set these properties at all (or set them to my own string). What is the best way to do that?

I see the method .setDocTitle() that allows me to set the Title property, but i didn't see methods for other properties.

Thanks,
Seth

how do I do a line break (ie: <br>) instead of a new paragraph (ie: <p>)

Hi there. I LOVE your library. It's so useful. Thank you so much for making it.

So, I'm trying to figure out how to do a single line break instead of the double line break that appears with each new paragraph (ie: pObj).

In HTML speak, it would be nice to be able to do a
instead of a

.

XLSX with cells containing newlines

Hi,

I want to set a cell to a text that contains newline characters. So I have a cell with the value set to 'X\nY' or 'X\r\n\Y' that I want to be shown as two lines when in Excel, but instead it shows as 'X Y' on the same line.

Any idea why this happens and how I can work around it?

officegen calling finalize event before document is flushed to disk

We are seeing consistent behavior where when officegen raises the finalize event, the file is not yet flushed to disk. For example, the finalize event will say the pptx is 745239 bytes, but if i do fs.stat on the file immediately afterwards, the size is 741962. a few milliseconds later, the file size is as expected. This is using officegen 0.2.8 on node 0.10.28. We do not see this behavior (or at least not consistently) on node 0.8.26.

our generation code looks like this:

            var out = fs.createWriteStream(paths.pptxFilePath);
            out.on('error', function (error) {
                onCompletion(error, null);
            });

            pptx.generate(out, {
                error: function (error) {
                    onCompletion(error, null);
                },
                finalize: function (bytesWritten) {
                    onCompletion(null, bytesWritten);
                }
            });

Do we need to do something different to know when it is available on disk? For now, i'm calling fs.stat in a loop with a small delay until the file sizes match (uggh).

Insert image in xlsx.

I am finding a way to insert an image to a n xlsx cell. Is there a way to do it? I am unable to find a proper way to do it with this module.

Version Bump?

Hi, You've made updates but have not done a version bump so the npm package manager installs the old version. Can you update the package.json etc.?

feature request: callback to generate()

Right now i have to listen on the finalize event to know when a pptx has been written out. it would be great to be able to pass a callback instead to generate. The reason is that i'm writing using streamline (https://github.com/Sage/streamlinejs) and it doesn't mesh well with event emitters. I wrote a wrapper for now that listens for the events, and maps it into a callback.

generate never exits

Hi, I'm using Node 10.38.

When running my code on the dev box, pptx.generate works fine and the output file is generated.

However on my Ubuntu Server it never really exits. Any reason why this happens?

Add image from url

Would be nice to be able to add images from url. Is that possible?

pObj.addImage('http://mycdn.com/logo.png')

[BUG] putPageBreak() crashed in docxgen

if ( (objs_list[i].data[j].text[0] == ' ') || (objs_list[i].data[j].
                                     ^
TypeError: Cannot read property '0' of undefined

putPageBreak() makes the TypeError. The detail of the code as follows,

var docx = officegen({
'type': 'docx'
});

var pObj = docx.createP();
pObj.addText('Hello,World ');
docx.putPageBreak();

var out = fs.createWriteStream ('out.docx');
out.on('error', function (err) {
console.log(err);
});
docx.generate(out);

Node 0.10.28

addImage for xlsx

Pretty straight forward really; it would be nice to insert and size an image into a cell

DOCX setting cx to percentage does not show image

DOCX
When adding an image, and attempting to set cx to a percentage, the image is not shown.

  • pObj.addImage( path.resolve(__dirname, 'file.jpg'), {cx: '45%'}); <--- not working

When adding an image, and setting cx to a number, the image is shown.

  • pObj.addImage( path.resolve(__dirname, 'orgHeader.jpg'), {cx: '600'}); <--- working

Support for headlines

Is there no support for Word headline/heading styles, or am I just missing something?

How to add a bar chart

How do I add a bar chart? The documentation is very inconsistent, it doesn't look like it's possible to add a barchart w/ the example code, is this correct? `slide.addBarChart(
{ title: 'Sample bar chart',
data: [ // each item is one serie
{
name: 'europe',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [2.5, 2.6, 2.8],
color: 'ff0000' // optional
},
{
name: 'namerica',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [2.5, 2.7, 2.9],
color: '00ff00' // optional
},
{
name: 'asia',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [2.1, 2.2, 2.4],
color: '0000ff' // optional
},
{
name: 'lamerica',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [0.3, 0.3, 0.3],
color: 'ffff00' // optional
},
{
name: 'meast',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [0.2, 0.3, 0.3],
color: 'ff00ff' // optional
},
{
name: 'africa',
labels: ['Y2003', 'Y2004', 'Y2005'],
values: [0.1, 0.1, 0.1],
color: '00ffff' // optional
}

]
}

);`

The text without space will not appear in docx

In Node 10.28, and LibreOffice

Nothing appear in docx without space after the words.

var pObj = docx.createP();
pObj.addText('Hello,World');

but it works like

var pObj = docx.createP();
pObj.addText('Hello,World ');

Do I have to add space?

Docx Templates/Content Replace

Hi,

This module looks great, I've had a browse through but not found anything. I'm looking to import a doc/docx file and replace conbtent with new content e.g '{{title}}' with 'My New Title'. Much like handlebars or other templating engines.

Is this possible with your module?

Cheers,
Ben.

support for larger png images in pptx

I had no issues adding a smaller logo .png with slide.addImage(). However, I tried several larger .png images from different sources and they didn't render in the output. I see no errors on the server.

font size is divided in half

Again, love the plugin. I noticed that if I used font_size 20, the font in word will actually end up being font size 10. Same for 40, it becomes 20 in word.

Compatibility: Latest Keynote won't open officegen generated pptx files

Hi, absolutely LOVE officegen. We'd love to use it to generate powerpoint slides in a new project that we're building.

However, there's a problem with the file format generated by pptx.

When I generate out the example pptx in the examples folder (or even just a basic single slide - see code below), and try to open it in the latest Keynote on Mac OS X I get the error:

“bad.pptx” can’t be opened.

Ideally, rather than generate both keynote and pptx files, we could just generate a single pptx file and rely on keynote compatibility to work with both.

Here's the bad.pptx that is generated that causes the issue.

When I open the bad.pptx in MS Powerpoint and save it back out as good.pptx here's what I get:

good.pttx

Here's the test js file that creates the bad.pptx:

var officegen = require('officegen');

var fs = require('fs');
var path = require('path');

var pptx = officegen ( 'pptx' );

var slide;
var pObj;

pptx.on ( 'finalize', function ( written ) {
            console.log ( 'Finish to create a PowerPoint file.\nTotal bytes created: ' + written + '\n' );
        });

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

pptx.setDocTitle ( 'Sample PPTX Document' );

// Let's create a new slide:
slide = pptx.makeNewSlide ();

slide.name = 'The first slide!';

// Change the background color:
slide.back = '000000';

// Declare the default color to use on this slide:
slide.color = 'ffffff';

// Basic way to add text string:
slide.addText ( 'Created using Officegen version ' + officegen.version );
slide.addText ( 'Fast position', 0, 20 );
slide.addText ( 'Full line', 0, 40, '100%', 20 );

var out = fs.createWriteStream ( 'bad.pptx' );

out.on ( 'error', function ( err ) {
    console.log ( err );
});

pptx.generate ( out );

Thanks for word.addImage()! Any chance of word.addTable() / addHTML() ?

Hi Ziv,

I'm already implementing the addimage feature for the system we're using, so thanks!

The ability to add either a table or an HTML fragment containing an HTML table would be amazingly useful to us! Any chance you feel generous enough to implement it?

Thanks again for the addImage() method!

latest archiver versions break pptx output in some cases

Officegen makes use of the archiver module. With the following module set (i.e. what you get from a default install of latest officegen right now), we get intermittent failures during pptx output. Specifically, we make the call to pptx.generate(), but it often hangs partway through, never emiting either the error or finalize events.

However, with achiver rolled back to 0.4.10, it works reliably. So it isn't an officegen issue per se.

The environment where we are testing and see issues with [email protected] is using node 0.8.26, running on linux (heroku dynos). Interestingly, the exact same code running on my OSX dev machine doesn't have this issue. Something subtle is happening here. It happens quite often with longer powerpoints; single slide ones seem to succeed.

We put in some logging within the officegen generate() code, and were able to see that it dies inside of archiver. The exact spot within the pptx export where it dies varies from run to run.

For now, we are working around this via an npm shrinkwrap file that locks us to the old [email protected].

The reason i'm raising the issue here is to warn officegen users, and to see if anyone else has anyone else hit this issue already, or can repro it.

I'd like to open a ticket with archiver, but i don't have a great repro case currently that doesn't involve a ton of other code.

Also, @Ziv-Barber you might want to lock officegen to archiver:~0.4.10 for now?

single instance images in pptx

If you insert the same image multiple times into a slide deck (say, an image you put once on each slide), you end up with N copies of that image in the pptx, instead of just one. This makes the file sizes larger. It would be great to store these in a single instance way.

XLSX Date support

Using the two dimensional array, dates are written as zero values:

var fs = require('fs');
var officegen = require('officegen');
var xlsx = officegen ( 'xlsx' );

xlsx.on ( 'finalize', function ( written ) {
            console.log ( 'Finish to create an Excel file.\nTotal bytes created: ' + written + '\n' );
        });

xlsx.on ( 'error', function ( err ) {
            console.log ( err );
        });

sheet = xlsx.makeNewSheet ();
sheet.name = 'Excel Test';

// The direct option - two-dimensional array:
sheet.data[0] = [];
sheet.data[0][0] = new Date();

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

out.on ( 'error', function ( err ) {
    console.log ( err );
});

xlsx.generate ( out );

published npm version 0.2.7 seems broken

When I do an npm install of the latest version (0.2.7) in npm and try to run any of the examples, they just exit without writing out the full file properly.

When I use what's in master, using a:

  "dependencies": {
    "officegen": "git+https://github.com/Ziv-Barber/officegen.git"
  },

It works fine.

Has master been published to npm?

Header / Footer

It would be great to build headers and footers into a word document. It looks like the xml syntax is the same if not restricted, except there's "header1.xml" and "footer1.xml" in addition to "document.xml". Thoughts?

Is it possible to and slides to an existing PPT document?

Hi, our client has an existing PPT template with lots of pre defined styles and layouts.

Is it possible to use this as the base for a our generated one? So the outputted ppt still has these styles and templates?

We don't need templating in the traditional sense (we make all the dynamic slides from scratch), we just want to keep / include the other styles and layouts into the final PPT.

m

Unreadable Content

After generating a Word Doc I get the following errors when trying to open it.

screen shot 2015-07-24 at 11 37 28 am

screen shot 2015-07-24 at 11 38 07 am

This is a very simple document with a single word in it. Do you have any idea what could be causing this?

The addImage method example is with wrong paramter

pObj.addImage ( path.resolve(__dirname, 'myFile.png' ) );
pObj.addImage ( path.resolve(__dirname, 'myFile.png', { cx: 300, cy: 200 } ) );

It should be :
pObj.addImage ( path.resolve(__dirname, 'myFile.png' ), { cx: 300, cy: 200 } );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.