Skip to content

Commit

Permalink
Version 0.2.6
Browse files Browse the repository at this point in the history
Automatically support line breaks for both PPTX and XLSX.
Fix a bug with using effects.
  • Loading branch information
Ziv-Barber committed Dec 9, 2013
1 parent b30fb9b commit 8481a0c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ https://groups.google.com/forum/?fromgroups#!forum/node-officegen
<a name="a8"/>
## History: ##

- Version 0.2.6:
- PowerPoint:
- Automatically support line breaks.
- Fixed a bug when using effects (shadows).
- Excell:
- Patch by arnesten: Automatically support line breaks if used in cell and also set appropriate row height depending on the number of line breaks.
- Version 0.2.5:
- Internal design changes that should not effect current implementations. To support future features.
- Bugs:
Expand Down
4 changes: 2 additions & 2 deletions examples/make_pptx.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ slide.addText ( [
// For a single text just pass a text string to addText:
slide.addText ( 'Office generator', { y: 66, x: 'c', cx: '50%', cy: 60, font_size: 48, color: '0000ff' } );

pObj = slide.addText ( 'Boom!!!', { y: 100, x: 10, cx: '70%', font_face: 'Wide Latin', font_size: 54, color: 'cc0000', bold: true, underline: true } );
pObj = slide.addText ( 'Boom\nBoom!!!', { y: 100, x: 10, cx: '70%', font_face: 'Wide Latin', font_size: 54, color: 'cc0000', bold: true, underline: true } );
pObj.options.y += 150;

// 2nd slide:
Expand All @@ -54,7 +54,7 @@ slide = pptx.makeNewSlide ();
// For every color property (including the back color property) you can pass object instead of the color string:
slide.back = { type: 'solid', color: '004400' };
pObj = slide.addText ( 'Office generator', { y: 'c', x: 0, cx: '100%', cy: 66, font_size: 48, align: 'center', color: { type: 'solid', color: '008800' } } );
pObj.setShadowEffect ( 'outerShadow', { top: true, left: true } );
pObj.setShadowEffect ( 'outerShadow', { bottom: true, right: true } );

slide = pptx.makeNewSlide ();

Expand Down
34 changes: 30 additions & 4 deletions lib/genpptx.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,32 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {
///
function cMakePptxOutTextCommand ( text_info, text_string, slide_obj ) {
var area_opt_data = cMakePptxOutTextData ( text_info, slide_obj );
return '<a:r><a:rPr lang="en-US"' + area_opt_data.font_size + area_opt_data.bold + area_opt_data.underline + ' dirty="0" smtClean="0"' + (area_opt_data.rpr_info != '' ? ('>' + area_opt_data.rpr_info) : '/>') + '<a:t>' + text_string.encodeHTML () + '</a:t></a:r>';
var outData = '<a:r><a:rPr lang="en-US"' + area_opt_data.font_size + area_opt_data.bold + area_opt_data.underline + ' dirty="0" smtClean="0"' + (area_opt_data.rpr_info != '' ? ('>' + area_opt_data.rpr_info) : '/>') + '<a:t>';

// Automatic support for newline - split it into multi-p:
var parsedText = text_string.split ( "\n" );
if ( parsedText.length > 1 ) {
var outTextData = '';
for ( var i = 0, total_size_i = parsedText.length; i < total_size_i; i++ ) {
outTextData += outData + parsedText[i].encodeHTML ();

if ( (i + 1) < total_size_i ) {
outTextData += '</a:t></a:r></a:p><a:p>';
} // Endif.
} // End of for loop.

outData = outTextData;

} else {
outData += text_string.encodeHTML ();
} // Endif.

var outBreakP = '';
if ( text_info.breakLine ) {
outBreakP += '</a:p><a:p>';
} // Endif.

return outData + '</a:t></a:r>' + outBreakP;
}

///
Expand Down Expand Up @@ -637,7 +662,7 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {
} // Endif.

if ( objs_list[i].options.effects ) {
for ( var ii = 0, total_size_ii = objs_list[i].options.effects.length; ii < total_size; ii++ ) {
for ( var ii = 0, total_size_ii = objs_list[i].options.effects.length; ii < total_size_ii; ii++ ) {
switch ( objs_list[i].options.effects[ii].type ) {
case 'outerShadow':
effectsList += cbGenerateEffects ( objs_list[i].options.effects[ii], 'outerShdw' );
Expand Down Expand Up @@ -695,11 +720,12 @@ function makePptx ( genobj, new_type, options, gen_private, type_info ) {
outString += cMakePptxOutTextCommand ( objs_list[i].options, objs_list[i].text, data.slide );

} else if ( objs_list[i].text ) {
outString += '<p:txBody>' + createBodyProperties ( objs_list[i].options ) + '<a:lstStyle/><a:p>' + outStyles;
var outBodyOpt = createBodyProperties ( objs_list[i].options );
outString += '<p:txBody>' + outBodyOpt + '<a:lstStyle/><a:p>' + outStyles;

for ( var j = 0, total_size_j = objs_list[i].text.length; j < total_size_j; j++ ) {
if ( objs_list[i].text[j] ) {
outString += cMakePptxOutTextCommand ( objs_list[i].text[j].options, objs_list[i].text[j].text, data.slide );
outString += cMakePptxOutTextCommand ( objs_list[i].text[j].options, objs_list[i].text[j].text, data.slide, outBodyOpt, outStyles );
} // Endif.
} // Endif.
} // Endif.
Expand Down
31 changes: 23 additions & 8 deletions lib/genxlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function makeXlsx ( genobj, new_type, options, gen_private, type_info ) {
// console.log ( genobj.generate_data.shared_strings.length );
} // Endif.
}

///
/// @brief ???.
///
Expand All @@ -153,7 +153,7 @@ function makeXlsx ( genobj, new_type, options, gen_private, type_info ) {
/// @return Text string.
///
function cbMakeXlsStyles ( data ) {
return gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml ( data ) + '<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="1"><font><sz val="11"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/></cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles><dxfs count="0"/><tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/></styleSheet>';
return gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml ( data ) + '<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="1"><font><sz val="11"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/><xf applyAlignment="1" borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"><alignment wrapText="1"/></xf></cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles><dxfs count="0"/><tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/></styleSheet>';
}

///
Expand Down Expand Up @@ -276,7 +276,7 @@ function makeXlsx ( genobj, new_type, options, gen_private, type_info ) {

return outCell;
}

///
/// @brief ???.
///
Expand Down Expand Up @@ -313,21 +313,36 @@ function makeXlsx ( genobj, new_type, options, gen_private, type_info ) {

for ( var rowId = 0, total_size_y = data.sheet.data.length; rowId < total_size_y; rowId++ ) {
if ( data.sheet.data[rowId] ) {
outString += '<row r="' + (rowId + 1) + '" spans="1:2">';
// Patch by arnesten <[email protected]>: Automatically support line breaks if used in cell + calculates row height:
var rowLines = 1;
data.sheet.data[rowId].forEach(function (cellData) {
if (typeof cellData === 'string') {
var candidate = cellData.split('\n').length;
rowLines = Math.max(rowLines, candidate);
}
});
outString += '<row r="' + (rowId + 1) + '" spans="1:' + (data.sheet.data[rowId].length) + '" ht="' + ( rowLines * 15 ) + '">';
// End of patch.

for ( var columnId = 0, total_size_x = data.sheet.data[rowId].length; columnId < total_size_x; columnId++ ) {
if ( typeof data.sheet.data[rowId][columnId] != 'undefined' ) {
var cellData = data.sheet.data[rowId][columnId];
if ( typeof cellData != 'undefined' ) {
var isString = '';
var cellOutData = '0';

switch ( typeof data.sheet.data[rowId][columnId] ) {
switch ( typeof cellData ) {
case 'number':
cellOutData = data.sheet.data[rowId][columnId];
cellOutData = cellData;
break;

case 'string':
isString = ' t="s"';
cellOutData = genobj.generate_data.cell_strings[data.id][rowId][columnId];
if (cellData.indexOf('\n') >= 0) {
isString = ' s="1" t="s"';
}
else {
isString = ' t="s"';
}
break;
} // End of switch.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "officegen",
"description": "Office Open XML Generator using Node.js streams. Supporting Microsoft Office 2007 and later Word (docx), PowerPoint (pptx,ppsx) and Excel (xlsx). This module is for all frameworks and environments. No need for any commandline tool - this module is doing everything inside it.",
"version": "0.2.5",
"version": "0.2.6",
"url": "https://github.com/Ziv-Barber/officegen",
"keywords": [
"officegen",
Expand Down

0 comments on commit 8481a0c

Please sign in to comment.