Name: officegen
Owner: Vivocha
Description: Node.js module: standalone Office Open XML files (Microsoft Office 2007 and later) generator for Word (docx), PowerPoint (pptx) and Excell (xlsx). The output is a stream.
Created: 2013-08-28 15:02:12.0
Updated: 2014-03-24 18:01:50.0
Pushed: 2014-07-28 07:39:41.0
Homepage: null
Size: 1159
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This module can generate Office Open XML files (the files been created by Microsoft Office 2007 and later). This module is not depend on any framework so you can use it for any kind of node.js application, even not web based. Also the output is a stream and not a file. This module should work on any environment that supporting node.js including Linux, OS-X and Windows and it's not depending on any output tool.
This module is a Javascript porting of my 'DuckWriteC++' library which doing the same in C++.
Please refer to the roadmap section for information on what will be added in the next versions.
This version only implementing basic features and there is no plugins API yet. You can fork this code if you want to but please beware that I'm in the middle of huge changing in the design of this module and it'll be better to wait for more stable releases if you want to improve it.
via npm:
m install officegen
This module is depending on:
Generating PowerPoint 2007 object:
pptx = require('../officegen.js').makegen ( { 'type': 'pptx' } );
Generating Word 2007 object:
docx = require('../officegen.js').makegen ( { 'type': 'docx' } );
Generating Excel 2007 object:
xlsx = require('../officegen.js').makegen ( { 'type': 'xlsx' } );
Now you should fill the object with data (we'll see below) and then you should call generate with an output stream to create the output Office document.
Example with pptx:
out = fs.createWriteStream ( 'out.pptx' );
.generate ( out );
Generating HTTP stream (no file been created):
http = require("http");
.createServer ( function ( request, response ) {
var pptx = require('../officegen.js').makegen (
{ 'type': 'pptx', 'onend': function ( written ) {
// ... (called after finishing to serve the user)
} } );
// ... (fill pptx with data)
pptx.generate ( response );
isten ( 3000 );
Creating a new slide:
e = pptx.makeNewSlide ();
The returned object from makeNewSlide representing a single slide. Use it to add objects into this slide. You must create at last one slide on your pptx/ppsx document.
Inside each slide you can place objects, for example: text box, shapes, images, etc.
Properties of the slide object itself:
The slide object supporting the following methods:
Read only methods:
Common properties that can be added to the options object for all the add based methods:
Font properties:
Text alignment properties:
Line/border extra properties (only effecting if the 'line' property exist):
The 'shape' property:
Normally every object is a rectangle but you can change that for every object using the shape property, or in case that you don't need to write any text inside that object, you can use the addShape method instead of addText. Use the shape property only if you want to use a shape other then the default and you also want to add text inside it.
Shapes list:
Please note that every color property can be either:
Adding images:
Just pass the image file name as the first parameter or addImage and the 2nd parameter, which is optional, is normal options objects and you can use all the common properties ('cx', 'cy', 'y', 'x', etc).
Examples:
Changing the background color of a slide:
e.back = '000088';
or:
e.back = { type: 'solid', color: '008800' };
Examples how to put text inside the new slide:
hange the background color:
e.back = '000000';
eclare the default color to use on this slide (default is black):
e.color = 'ffffff';
asic way to add text string:
e.addText ( 'This is a test' );
e.addText ( 'Fast position', 0, 20 );
e.addText ( 'Full line', 0, 40, '100%', 20 );
dd text box with multi colors and fonts:
e.addText ( [
{ text: 'Hello ', options: { font_size: 56 } },
{ text: 'World!', options: { font_size: 56, font_face: 'Arial', color: 'ffff00' } }
], { cx: '75%', cy: 66, y: 150 } );
lease note that you can pass object as the text parameter to addText.
e.addText ( 'Office generator', {
y: 66, x: 'c', cx: '50%', cy: 60, font_size: 48,
color: '0000ff' } );
e.addText ( 'Boom!!!', {
y: 250, x: 10, cx: '70%',
font_face: 'Wide Latin', font_size: 54,
color: 'cc0000', bold: true, underline: true } );
All the text data in Word is saved in paragraphs. To add a new paragraph:
pObj = docx.createP ();
Paragraph options:
.options.align = 'center'; // Also 'right' or 'jestify'.
Every list item is also a paragraph so:
pObj = docx.createListOfDots ();
pObj = docx.createListOfNumbers ();
Now you can fill the paragraph object with one or more text strings using the addText method:
.addText ( 'Simple' );
.addText ( ' with color', { color: '000088' } );
.addText ( ' and back color.', { color: '00ffff', back: '000088' } );
.addText ( 'Bold + underline', { bold: true, underline: true } );
.addText ( 'Fonts face only.', { font_face: 'Arial' } );
.addText ( ' Fonts face and size.', { font_face: 'Arial', font_size: 40 } );
To add a page break:
.putPageBreak ();
t = xlsx.makeNewSheet ();
t.name = 'My Excel Data';
Fill cells:
sing setCell:
t.setCell ( 'E7', 340 );
t.setCell ( 'G102', 'Hello World!' );
irect way:
t.data[0] = [];
t.data[0][0] = 1;
t.data[0][1] = 2;
t.data[1] = [];
t.data[1][3] = 'abc';
This section on the readme file will describe how to hack into the code. Right now please refer to the code itself. More information will be added later.
Please visit the officegen Google Group:
https://groups.google.com/forum/?fromgroups#!forum/node-officegen
Features todo:
(The MIT License)
Copyright (c) 2013 Ziv Barber;
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.