Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Table formatting options set to default on empty cells #20

Closed
rikvdk opened this issue Jan 3, 2017 · 5 comments
Closed

Table formatting options set to default on empty cells #20

rikvdk opened this issue Jan 3, 2017 · 5 comments
Assignees

Comments

@rikvdk
Copy link

rikvdk commented Jan 3, 2017

I have a problem with table options getting defaulted on empty table cells. Consider the following simple code which creates a table:

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

var row = [42, 'foo', '', null];
var options = { font_size: 12 };
slide.addTable(row, options);

pptx.save();

I expect that all 4 cells get all the formatting options specified in options. However, the result defaults the styling of the last 2 cells ('' and null). Giving those font size 18.

This might happend for all formatting options. The only other option I was using was font_face which got defaulted to Arial.

@gitbrent
Copy link
Owner

gitbrent commented Jan 4, 2017

Thanks for reporting this!

Turns out, this is feature from Microsoft (the Apple Slides app formats all cells uniformly). The exact same code is generated for each of the table cells, however, since I was using an empty string when the cell was null, blank, etc., PPT just used it's default (?) of Arial 18pt.

I've updated the addTable() code to insert a space (' ') instead and that seems to enable the cell font size to "stick" now, so new text inserted inherits from the space's formatting.

@rikvdk
Copy link
Author

rikvdk commented Jan 4, 2017

If I empty a cell in PowerPoint it does remove the styling, but with a table created and styled in PowerPoint itself it doesn't. I guess you format the tables in a different way than PowerPoint does it.

Adding a space while a little annoying is a fine solution I guess.

@gitbrent gitbrent closed this as completed Jan 5, 2017
@Szymon-dziewonski
Copy link

I have the same problem, but still when i put empty space " " or "\u00A0" doesnt matter what coding for space styling on this cell is removed

@gitbrent
Copy link
Owner

Hi @Szymon-dziewonski ,

Can you tell me which version of PowerPoint you are using, what version of PptxGenJS you have, and the code being used? A screencap of the output would also be helpful.

@Szymon-dziewonski
Copy link

Hey, yeah sure sorry I didnt done it in first place

Powerpoint 2010 v14.0.7015.1000 (32-bit)
PPtx ver 1.2.2

Script for creating desirable tables

shape = {
table: function (pageName, table_size, table_array, x, y, w, colW) {
    var header_fz = 12,
      body_fz = 9,
      header_margin = [10, 5, 10, 5],
      body_margin = [4, 4, 4, 4];

    if (table_size === "small") {
      header_fz = 9;
      body_fz = 8;
      header_margin = [2, 2, 2, 2];
      body_margin = [1, 1, 1, 1];
    }

    var header_options = {
      fill: bright_blue,
      font_size: header_fz,
      font_face: 'Arial',
      color: "ffffff",
      margin: header_margin,
      bold: true
    };
    var left_column_options = {
      fill: bright_blue,
      font_size: body_fz,
      font_face: 'Arial',
      color: "ffffff",
      margin: body_margin,
      bold: true
    };

    for (var i = 0; i < table_array[0].length; i++) {
      table_array[0][i] = {text: table_array[0][i], options: header_options};
    }
    for (var i = 1; i < table_array.length; i++) {
      table_array[i][0] = {text: table_array[i][0], options: left_column_options};
    }

    pageName.addTable(table_array, {
      x: x,
      y: y,
      w: w,
      fill: 'F7F7F7',
      font_size: body_fz,
      font_face: 'Arial',
      color: '000000',
      align: 'l',
      valign: 'm',
      margin: body_margin,
      colW: colW,
      border: {pt: "1", color: "ffffff"}
    });
}
var table_arr= [
        [" ", "Description"],
        ["1", "first row"],
        ["2", "second row"]
      ];
      shape.table(process_scheme, "small", table_arr, 0.5, 1.9, 1.8, [0.2, 1.6]);

And how it looks here on pptx file
image

When i place some sign there in blank space lets say "*"
image

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants