officegen

Open source

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.

Contribute


Become a financial contributor.

Financial contributions

Custom contribution

Donation

Make a custom one time or recurring contribution.
Recurring contribution

backer

Become a backer for $5.00 per month and help us sustain our activities!

Starts at

$5 USD / month

Recurring contribution

sponsor

Become a sponsor for $100.00 per month and help us sustain our activities!

Starts at

$100 USD / month

What's new with officegen

Stay up to dates with our latest activities and progress.

Version 0.4.8 is out!

This version was more upgrade of all the dependencies and also more documentation.The next release (very soon!) will be of new features.
Read more
Published on March 31, 2019 by Ziv Barber

Conversations

Let’s get the ball rolling! This is where things get planned and sometimes this is where things get done. Ask questions, thank people for their efforts, and contribute your skills to the service of the community.

officegen is all of us

Our contributors 1

Everyone who has supported officegen. Individuals and organizations that believe in –and take ownership of– our purpose.

About

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')

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

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

// 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:

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

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

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

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:
pptx.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)

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)

For full documentation: https://github.com/Ziv-Barber/officegen/blob/master/manual/README.md