Skip to content

Commit

Permalink
Issue #169 - no border for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
GitBrent authored and GitBrent committed Sep 7, 2017
1 parent b7afab5 commit b50dccc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- New chart options: catAxisLineShow [\#152](https://github.com/gitbrent/PptxGenJS/pull/152) ([amgault](https://github.com/amga))
- New Master Slide Layouts [\#161](https://github.com/gitbrent/PptxGenJS/pull/161) ([kajda90](https://github.com/kajda90))
- New chart feature: New Legend/Title Options [\#165](https://github.com/gitbrent/PptxGenJS/pull/165) ([clubajax](https://github.com/clubajax))
- Add no border option to tables [\#169](https://github.com/gitbrent/PptxGenJS/issues/169) ([eddyclock](https://github.com/eddyclock))
- Chart: Escape Labels XML [\#171](https://github.com/gitbrent/PptxGenJS/pull/171) ([kyrrigle](https://github.com/kyrrigle))


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ tables. Use this option to ensure there is no wasted space and to guarantee a pr
### Table Cell Formatting
* Table cells can be either a plain text string or an object with text and options properties
* When using an object, any of the formatting options above can be passed in `options` and will apply to that cell only
* Cell borders can be removed (aka: borderless table) by passing a `pt` value of `0` (Ex: `border:{ pt:0 }`)
* Cell borders can be removed (aka: borderless table) by passing a 'none' (Ex: `border:'none'`)

Bullets and word-level formatting are supported inside table cells. Passing an array of objects with text/options values
as the `text` value allows fine-grained control over the text inside cells.
Expand Down
13 changes: 10 additions & 3 deletions dist/pptxgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var PptxGenJS = function(){
var REGEX_HEX_COLOR = /^[0-9a-fA-F]{6}$/;
var JSZIP_OUTPUT_TYPES = ['arraybuffer', 'base64', 'binarystring', 'blob', 'nodebuffer', 'uint8array']; /** @see https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html */
//
var DEF_CELL_BORDER = { color:"666666" };
var DEF_CELL_MARGIN_PT = [3, 3, 3, 3]; // TRBL-style
var DEF_FONT_SIZE = 12;
var DEF_FONT_TITLE_SIZE = 18;
Expand Down Expand Up @@ -828,7 +829,13 @@ var PptxGenJS = function(){
strXml += '<a:tc'+ cellColspan + cellRowspan +'>' + genXmlTextBody(cell) + '<a:tcPr'+ cellMargin + cellValign +'>';

// 5: Borders: Add any borders
if ( cellOpts.border && typeof cellOpts.border === 'string' ) {
if ( cellOpts.border && typeof cellOpts.border === 'string' && cellOpts.border.toLowerCase() == 'none' ) {
strXml += ' <a:lnL w="0" cap="flat" cmpd="sng" algn="ctr"><a:noFill/></a:lnL>';
strXml += ' <a:lnR w="0" cap="flat" cmpd="sng" algn="ctr"><a:noFill/></a:lnR>';
strXml += ' <a:lnT w="0" cap="flat" cmpd="sng" algn="ctr"><a:noFill/></a:lnT>';
strXml += ' <a:lnB w="0" cap="flat" cmpd="sng" algn="ctr"><a:noFill/></a:lnB>';
}
else if ( cellOpts.border && typeof cellOpts.border === 'string' ) {
strXml += ' <a:lnL w="'+ ONEPT +'" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:srgbClr val="'+ cellOpts.border +'"/></a:solidFill></a:lnL>';
strXml += ' <a:lnR w="'+ ONEPT +'" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:srgbClr val="'+ cellOpts.border +'"/></a:solidFill></a:lnR>';
strXml += ' <a:lnT w="'+ ONEPT +'" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:srgbClr val="'+ cellOpts.border +'"/></a:solidFill></a:lnT>';
Expand All @@ -837,7 +844,7 @@ var PptxGenJS = function(){
else if ( cellOpts.border && Array.isArray(cellOpts.border) ) {
$.each([ {idx:3,name:'lnL'}, {idx:1,name:'lnR'}, {idx:0,name:'lnT'}, {idx:2,name:'lnB'} ], function(i,obj){
if ( cellOpts.border[obj.idx] ) {
var strC = '<a:solidFill><a:srgbClr val="'+ ((cellOpts.border[obj.idx].color) ? cellOpts.border[obj.idx].color : '666666') +'"/></a:solidFill>';
var strC = '<a:solidFill><a:srgbClr val="'+ ((cellOpts.border[obj.idx].color) ? cellOpts.border[obj.idx].color : DEF_CELL_BORDER.color) +'"/></a:solidFill>';
var intW = (cellOpts.border[obj.idx] && (cellOpts.border[obj.idx].pt || cellOpts.border[obj.idx].pt == 0)) ? (ONEPT * Number(cellOpts.border[obj.idx].pt)) : ONEPT;
strXml += '<a:'+ obj.name +' w="'+ intW +'" cap="flat" cmpd="sng" algn="ctr">'+ strC +'</a:'+ obj.name +'>';
}
Expand All @@ -846,7 +853,7 @@ var PptxGenJS = function(){
}
else if ( cellOpts.border && typeof cellOpts.border === 'object' ) {
var intW = (cellOpts.border && (cellOpts.border.pt || cellOpts.border.pt == 0) ) ? (ONEPT * Number(cellOpts.border.pt)) : ONEPT;
var strClr = '<a:solidFill><a:srgbClr val="'+ ((cellOpts.border.color) ? cellOpts.border.color.replace('#','') : '666666') +'"/></a:solidFill>';
var strClr = '<a:solidFill><a:srgbClr val="'+ ((cellOpts.border.color) ? cellOpts.border.color.replace('#','') : DEF_CELL_BORDER.color) +'"/></a:solidFill>';
var strAttr = '<a:prstDash val="';
strAttr += ((cellOpts.border.type && cellOpts.border.type.toLowerCase().indexOf('dash') > -1) ? "sysDash" : "solid" );
strAttr += '"/><a:round/><a:headEnd type="none" w="med" len="med"/><a:tailEnd type="none" w="med" len="med"/>';
Expand Down
2 changes: 1 addition & 1 deletion examples/pptxgenjs-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ function genSlides_Table(pptx) {
slide.addTable( [['margin:[40,5,5,20]']], { x:7.5, y:1.1, margin:[40,5,5,20], w:2.2, fill:'F1F1F1' } );
slide.addTable( [['margin:[80,5,5,10]']], { x:10.5,y:1.1, margin:[80,5,5,10], w:2.2, fill:'F1F1F1' } );

slide.addTable( [{text:'number zero:', options:{margin:5}}, {text:0, options:{marginPt:5}}], { x:0.5, y:1.9, w:3, fill:'f2f9fc', colW:[2,1] } );
slide.addTable( [{text:'number zero:', options:{margin:5}}, {text:0, options:{marginPt:5}}], { x:0.5, y:1.9, w:3, fill:'f2f9fc', border:'none', colW:[2,1] } );
slide.addTable( [{text:'text-obj margin:0', options:{margin:0}}], { x:4.0, y:1.9, w:2, fill:'f2f9fc' } );

// Test margin option when using both plain and text object cells
Expand Down

0 comments on commit b50dccc

Please sign in to comment.