diff --git a/README.md b/README.md index 514cbad9..ed5eabfb 100644 --- a/README.md +++ b/README.md @@ -475,6 +475,12 @@ https://groups.google.com/forum/?fromgroups#!forum/node-officegen ## 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: diff --git a/examples/make_pptx.js b/examples/make_pptx.js index 5c8ae111..4c98e487 100644 --- a/examples/make_pptx.js +++ b/examples/make_pptx.js @@ -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: @@ -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 (); diff --git a/lib/genpptx.js b/lib/genpptx.js index ea1286f2..b2647e24 100644 --- a/lib/genpptx.js +++ b/lib/genpptx.js @@ -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 '' + area_opt_data.rpr_info) : '/>') + '' + text_string.encodeHTML () + ''; + var outData = '' + area_opt_data.rpr_info) : '/>') + ''; + + // 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 += ''; + } // Endif. + } // End of for loop. + + outData = outTextData; + + } else { + outData += text_string.encodeHTML (); + } // Endif. + + var outBreakP = ''; + if ( text_info.breakLine ) { + outBreakP += ''; + } // Endif. + + return outData + '' + outBreakP; } /// @@ -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' ); @@ -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 += '' + createBodyProperties ( objs_list[i].options ) + '' + outStyles; + var outBodyOpt = createBodyProperties ( objs_list[i].options ); + outString += '' + outBodyOpt + '' + 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. diff --git a/lib/genxlsx.js b/lib/genxlsx.js index ce26f5b5..1cd50a31 100644 --- a/lib/genxlsx.js +++ b/lib/genxlsx.js @@ -143,7 +143,7 @@ function makeXlsx ( genobj, new_type, options, gen_private, type_info ) { // console.log ( genobj.generate_data.shared_strings.length ); } // Endif. } - + /// /// @brief ???. /// @@ -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 ) + ''; + return gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml ( data ) + ''; } /// @@ -276,7 +276,7 @@ function makeXlsx ( genobj, new_type, options, gen_private, type_info ) { return outCell; } - + /// /// @brief ???. /// @@ -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 += ''; + // Patch by arnesten : 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 += ''; + // 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. diff --git a/package.json b/package.json index 17f8925a..30f637bd 100644 --- a/package.json +++ b/package.json @@ -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",