Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSZip rather than file system for embedded Excel for charts #83

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
.DS_Store
out.*
.idea/

\#*#
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $ git clone git://github.com/protobi/officegen.git
via npm:

```bash
$ npm install protobi/officegen
$ npm install officegen
```

This module is depending on:
Expand Down Expand Up @@ -441,7 +441,8 @@ slide.addChart(
renderType: 'column',
valAxisTitle: 'Costs/Revenues ($)',
catAxisTitle: 'Category',
valAxisNumFmt: '$0
valAxisNumFmt: '$0',
valAxisMaxValue: 24,
data: [ // each item is one serie
{
name: 'Income',
Expand Down
20 changes: 11 additions & 9 deletions lib/basicgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

require("setimmediate"); // To be compatible with all versions of node.js

var sys = require('sys');
var sys = require('util');
var events = require('events');

var Transform = require('stream').Transform || require('readable-stream/transform');
Expand Down Expand Up @@ -69,8 +69,8 @@ int_officegen_globals.resParserTypes = {};
///
/// @param[in] options List of configuration options (see in the description of this function).
///
officegen = function ( options ) {
if ( false === ( this instanceof officegen )) {
var officegen = function ( options ) {
if ( false === ( this instanceof officegen )) {
return new officegen ( options );
} // Endif.

Expand Down Expand Up @@ -103,7 +103,7 @@ officegen = function ( options ) {
///
/// @param[in] options The options to configure.
///
function setOptions ( object, source ) {
function setOptions ( object, source ) {// what is source for
object = object || {};

var objectTypes = {
Expand All @@ -117,15 +117,15 @@ officegen = function ( options ) {

function isObject (value) {
return !!(value && objectTypes[typeof value]);
};
}

function keys (object) {
if (!isObject(object)) {
return [];
}

return Object.keys(object);
};
}

var index;
var iterable = object;
Expand All @@ -135,13 +135,15 @@ officegen = function ( options ) {
var argsIndex = 0;
var argsLength = args.length;

//loop variables
var ownIndex = -1;
var ownProps = objectTypes[typeof iterable] && keys(iterable);
var length = ownProps ? ownProps.length : 0;

while (++argsIndex < argsLength) {
iterable = args[argsIndex];

if (iterable && objectTypes[typeof iterable]) {
var ownIndex = -1;
var ownProps = objectTypes[typeof iterable] && keys(iterable);
var length = ownProps ? ownProps.length : 0;

while (++ownIndex < length) {
index = ownProps[ownIndex];
Expand Down
47 changes: 45 additions & 2 deletions lib/gendocx.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ function makeDocx ( genobj, new_type, options, gen_private, type_info ) {
outString += '<wp:inline distT="0" distB="0" distL="0" distR="0">';
outString += '<wp:extent cx="' + (objs_list[i].data[j].options.cx * pixelToEmu) + '" cy="' + (objs_list[i].data[j].options.cy * pixelToEmu) + '"/>';
outString += '<wp:effectExtent l="19050" t="0" r="9525" b="0"/>';
outString += '<wp:docPr id="' + (objs_list[i].data[j].image_id + 1) + '" name="Picture ' + objs_list[i].data[j].image_id + '" descr="Picture ' + objs_list[i].data[j].image_id + '"/>';

outString += '<wp:docPr id="' + (objs_list[i].data[j].image_id + 1) + '" name="Picture ' + objs_list[i].data[j].image_id + '" descr="Picture ' + objs_list[i].data[j].image_id + '">';
if(objs_list[i].data[j].link_rel_id){
outString += '<a:hlinkClick xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" r:id="rId'+objs_list[i].data[j].link_rel_id+'"/>';
}
outString += '</wp:docPr>';

outString += '<wp:cNvGraphicFramePr>';
outString += '<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>';
outString += '</wp:cNvGraphicFramePr>';
Expand Down Expand Up @@ -284,7 +290,29 @@ function makeDocx ( genobj, new_type, options, gen_private, type_info ) {
outString += '</w:p>';
} // End of for loop.

outString += '<w:p w:rsidR="00A02F19" w:rsidRDefault="00A02F19"/><w:sectPr w:rsidR="00A02F19" w:rsidSect="00A02F19"><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720" w:gutter="0"/><w:cols w:space="720"/><w:docGrid w:linePitch="360"/></w:sectPr></w:body></w:document>';
outString += '<w:p w:rsidR="00A02F19" w:rsidRDefault="00A02F19"/>';

// Landscape orientation support
if(options.orientation && options.orientation == 'landscape'){
outString +=
'<w:sectPr w:rsidR="00A02F19" w:rsidSect="00897086">' +
'<w:pgSz w:w="15840" w:h="12240" w:orient="landscape"/>' +
'<w:pgMar w:top="1800" w:right="1440" w:bottom="1800" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>' +
'<w:cols w:space="720"/>' +
'<w:docGrid w:linePitch="360"/>' +
'</w:sectPr>';
}else{
outString +=
'<w:sectPr w:rsidR="00A02F19" w:rsidSect="00A02F19">' +
'<w:pgSz w:w="12240" w:h="15840"/>' +
'<w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720" w:gutter="0"/>' +
'<w:cols w:space="720"/>' +
'<w:docGrid w:linePitch="360"/>' +
'</w:sectPr>';
}

outString += '</w:body></w:document>';

return outString;
}

Expand Down Expand Up @@ -504,11 +532,26 @@ function makeDocx ( genobj, new_type, options, gen_private, type_info ) {
);
} // Endif.

if ((opt || {}).link) {

var link_rel_id = gen_private.type.msoffice.rels_app.length + 1;

gen_private.type.msoffice.rels_app.push({
type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
target: opt.link,
targetMode: 'External'
});

newP.data[objNum].link_rel_id = link_rel_id;

} // Endif.

newP.data[objNum].image_id = image_id;
newP.data[objNum].rel_id = image_rel_id;
};

genobj.data[genobj.data.length] = newP;

return newP;
};

Expand Down
28 changes: 18 additions & 10 deletions lib/genpptx.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {

out_obj.font_size = '';
out_obj.bold = '';
out_obj.italic = '';
out_obj.strike = '';
out_obj.underline = '';
out_obj.rpr_info = '';
out_obj.char_spacing = '';
Expand All @@ -433,6 +435,14 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {
out_obj.bold = ' b="1"';
} // Endif.

if ( text_info.italic ) {
out_obj.italic = ' i="1"';
} // Endif.

if ( text_info.strike ) {
out_obj.strike = ' strike="sngStrike"';
} // Endif.

if ( text_info.underline ) {
out_obj.underline = ' u="sng"';
} // Endif.
Expand Down Expand Up @@ -487,8 +497,12 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {
///
function cMakePptxOutTextCommand ( text_info, text_string, slide_obj, slide_num ) {
var area_opt_data = cMakePptxOutTextData ( text_info, slide_obj );
var textStyles = ['font_size', 'strike', 'italic', 'bold', 'underline', 'char_spacing'].reduce(function(acc, attr) {
return acc + area_opt_data[attr]
}, '');
var parsedText;
var startInfo = '<a:rPr lang="en-US"' + area_opt_data.font_size + area_opt_data.bold + area_opt_data.underline + area_opt_data.char_spacing + ' dirty="0" smtClean="0"' + (area_opt_data.rpr_info != '' ? ('>' + area_opt_data.rpr_info) : '/>') + '<a:t>';
var startInfo = '<a:rPr lang="en-US"' + textStyles + ' dirty="0" smtClean="0"' +
(area_opt_data.rpr_info != '' ? ('>' + area_opt_data.rpr_info) : '/>') + '<a:t>';
var endTag = '</a:r>';
var outData = '<a:r>' + startInfo;

Expand Down Expand Up @@ -1552,14 +1566,8 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {
});

workbook.save(function(err){
if (err)
{
workbook.cancel();
}
else
{
callback();
}
if (err) return errorCallback(err);
else return callback();
});
}

Expand Down Expand Up @@ -1665,7 +1673,7 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {
/// @param[in] y_size ???.
/// @param[in] image_format_type ???.
///
slideObj.addImage = function ( image_path, opt, y_pos, x_size, y_size, image_format_type ) {
slideObj. addImage = function ( image_path, opt, y_pos, x_size, y_size, image_format_type ) {
var objNumber = gen_private.pages[pageNumber].data.length;
var image_type = (typeof image_format_type == 'string') ? image_format_type : 'png';
var defWidth, defHeight = 0;
Expand Down
8 changes: 7 additions & 1 deletion lib/genxlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@ function makeXlsx ( genobj, new_type, options, gen_private, type_info ) {
// outString += '<selection activeCell="A1" sqref="A1"/>';
outString += '</sheetViews><sheetFormatPr defaultRowHeight="15"/>';

// BMK_TODO: <cols><col min="2" max="2" width="19" customWidth="1"/></cols>
if ( data.sheet.width ) {
outString += '<cols>';
for ( var i = 0; i < data.sheet.width.length; i++ ) {
outString += "<col min=\"" + (i+1) + "\" max=\"" + (i+1) + "\" width=\"" + data.sheet.width[i] + "\" customWidth=\"1\"/>";
}
outString += '</cols>';
}

outString += '<sheetData>';

Expand Down
Loading