From e7927a8f08603f759fb5f0afe9553fef573313f2 Mon Sep 17 00:00:00 2001 From: GitBrent Date: Sat, 5 Aug 2017 22:32:21 -0500 Subject: [PATCH] Fix for Issue #122 Area and Line chart data (the embedded xlsx) is editable in O365 now. --- dist/pptxgen.js | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/dist/pptxgen.js b/dist/pptxgen.js index a197321a2..0844b50c7 100644 --- a/dist/pptxgen.js +++ b/dist/pptxgen.js @@ -62,7 +62,7 @@ if ( NODEJS ) { var PptxGenJS = function(){ // CONSTANTS var APP_VER = "1.7.0-beta"; - var APP_REL = "20170803"; + var APP_REL = "20170805"; // var MASTER_OBJECTS = { 'chart': { name:'chart' }, @@ -242,21 +242,21 @@ var PptxGenJS = function(){ zipExcel.file("xl/theme/theme1.xml", '\n' ); - zipExcel.file("xl/workbook.xml", '\n'); + zipExcel.file("xl/workbook.xml", '\n'); // `sharedStrings.xml` var strSharedStrings = ''; - strSharedStrings += ''; + strSharedStrings += ''; { - // A: Pie name comes before labels - if ( rel.opts.type == 'pie' ) { - strSharedStrings += ''+ (rel.data[0].name || ' ') +''; + // A: Pie `name` [Series] comes before `label`s + if ( rel.opts.type == 'area' || rel.opts.type == 'line' || rel.opts.type == 'pie' ) { + rel.data.forEach(function(objData,idx){ strSharedStrings += ''+ (objData.name || ' ') +''; }); } - // B: Lables + // B: Labels rel.data[0].labels.forEach(function(label,idx){ strSharedStrings += ''+ label +''; }); - // C: Bar series names come after labels + // C: Bar `name` [Series] come after `label`s if ( rel.opts.type == 'bar' ) { rel.data.forEach(function(objData,idx){ strSharedStrings += ''+ (objData.name || ' ') +''; }); } @@ -266,8 +266,16 @@ var PptxGenJS = function(){ var strSheetXml = ''; strSheetXml += ''; - strSheetXml += ''; - strSheetXml += ''; + strSheetXml += ''; + strSheetXml += ''; + strSheetXml += ''; + strSheetXml += ''; + strSheetXml += ''; + strSheetXml += ' '; + rel.data.forEach(function(){ + strSheetXml += ' '; + }); + strSheetXml += ''; strSheetXml += ''; if ( rel.opts.type == 'area' || rel.opts.type == 'line' ) { @@ -278,7 +286,7 @@ var PptxGenJS = function(){ { name:'Grn', labels:['Jan..May-17'], values:[33,32,42,53,63] } ]; */ - /* EX: OUTPUT: barChart Worksheet: + /* EX: OUTPUT: lineChart Worksheet: -|---A---|--B--|--C--|--D--| 1| | Red | Amb | Grn | 2|Jan-17 | 11| 22| 33| @@ -290,10 +298,11 @@ var PptxGenJS = function(){ */ // A: Create header row first (NOTE: Start at index=1 as headers cols start with 'B') strSheetXml += ''; + strSheetXml += ''; for (var idx=1; idx<=rel.data.length; idx++) { - // TODO: FIXME: Max cols is 52 - strSheetXml += ''; - strSheetXml += ''+ idx +''; + // FIXME: Max cols is 52 + strSheetXml += ''; // NOTE: use `t="s"` for label cols! + strSheetXml += ''+ (idx-1) +''; strSheetXml += ''; } strSheetXml += ''; @@ -303,12 +312,12 @@ var PptxGenJS = function(){ // Leading col is reserved for the label, so hard-code it, then loop over col values strSheetXml += ''; strSheetXml += ''; - strSheetXml += ''+ (rel.data[0].values.length + idx - 1) +''; + strSheetXml += ''+ (rel.data.length + idx - 2) +''; strSheetXml += ''; rel.data.forEach(function(col,idy){ // TODO: FIXME: Max cols is 52 - strSheetXml += ''; - strSheetXml += ''+ rel.data[idy].values[idx] +''; + strSheetXml += ''; + strSheetXml += ''+ rel.data[idy].values[idx-2] +''; strSheetXml += ''; }); strSheetXml += ''; @@ -399,6 +408,8 @@ var PptxGenJS = function(){ } strSheetXml += ''; + strSheetXml += ''; + strSheetXml += ''; strSheetXml += '\n'; zipExcel.file("xl/worksheets/sheet1.xml", strSheetXml);