gitbrent / PptxGenJS

Create PowerPoint presentations with a powerful, concise JavaScript API.
https://gitbrent.github.io/PptxGenJS/
MIT License
2.9k stars 633 forks source link

cannot add an array of text objects using addText() for addSlidesForTable() #487

Open rickykoh opened 5 years ago

rickykoh commented 5 years ago

Hi Team,

I'm aware of being able to use the addText() option for the method addSlidesForTable() to include text in master slide, as per issue #427 .

var pptx = new PptxGenJS();
var objOpts = {x:1.10, y:0.8, h:"100%", master:"MASTER_SLIDE", w:10.3};
objOpts.addText = { 
 text: "Table Title", 
 opts: { 
   x: 0.5, 
   y: 0.5, 
   fontSize:12 
 } 
};
pptx.addSlidesForTable('table-id', objOpts);

However, that only allow adding of one text object but does not allow an array of text objects, as shown below. An array of text objects will result in no text being inserted into the slide at all.

objOpts.addText = ([
 {
   text: "Text 1",
   opts: {
         x: 0.5,
         y: 0.5,
         fontSize: 18
     }
 }, {
    text: "Text 2",
    opts: {
         x: 0.5,
         y: 1.0,
         fontSize: 20
     }
 }
]);

I am aware that I can also make use of the objects option in pptx.defineSlideMaster() to add texts, however that would result in the added text not editable in the slide. (I would like it to be editable)

pptx.defineSlideMaster({
 title: "MASTER_SLIDE",
 objects: [{
  text: {
   text: "Text 1",
   options: {
     x: 0.5,
     y: 0.5,
     fontSize: 18
   }
  }
 }, {
  text: {
    text: "Text 1",
    options: {
     x: 0.5,
     y: 0.5,
     fontSize: 18
   }
  }
 }]
});

Kindly assist.

Thank you.

gitbrent commented 5 years ago

Master text isn't editable by design. You'll want to use regular objects and not create Slide Masters.

rickykoh commented 5 years ago

Hi, thanks for your reply.

As I am using the method addSlidesForTable() to create a HTML table, is there any ways I can add multiple text objects to the same slide with the HTML table?

As I've mentioned above that it seems like only one text object can be included instead of multiple text objects.

I've looked through the library codes and am wondering if it's possible to check whether the opts.addText is an array and perform a loop for newSlide.addText() at line 5309:

if ( opts.addText ) newSlide.addText( opts.addText.text, (opts.addText.opts || {}) );

gitbrent commented 5 years ago

The addSlidesForTable() method merely converts an HMTL table into PPT slides. It's not meant to be used to build up complicated formatting, etc.

You'll want to use addTable() and format from there. See examples for code.

screen shot 2019-01-27 at 11 50 43

screen shot 2019-01-27 at 11 50 49

elezotte commented 3 years ago

Reading through this thread I'm confused as to whether it's possible to add more than one piece of editable text to a slide generated via tableToSlides. The normal usage of the slide.addText method accepts an array of objects whereas the tableToSlides method only accept one object. Is this intentional or am I simply using it wrong?

gitbrent commented 3 years ago

@elezotte - this section of the code has aged quite a bit and wasn't kept up to date with its peer methods.

I'll have to update it to handle array instead of solitary objects.

https://github.com/gitbrent/PptxGenJS/blob/0f115ab46bd4f6cb18e26f418194597688b19402/src/gen-tables.ts#L551-L554

zabamark commented 3 months ago

Hi, I know this is kinda old, but was it resolved?