officegen icon indicating copy to clipboard operation
officegen copied to clipboard

hi! could this can merge cells for table?

Open 18876293672 opened this issue 4 years ago • 4 comments

Environment

  1. node -v: [fill]
  2. npm -v: [fill]
  3. npm ls officegen: [fill]
  4. Operating system: [fill]
  5. Microsoft Office version: [fill]
  6. Problem with Powerpoint, Excel or Word document: [fill]

Steps to Reproduce

[fill]

Expected Behavior

[fill]

Actual Behavior

[fill]


An example code will be the best. The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself.

18876293672 avatar Sep 10 '19 08:09 18876293672

Hi, I had a similar problem to group in pptx My solution was modify the source code of officegen:

At genofficetable.js in lib/pptx

_getCell: function(val, options, idx, row_idx) {
...
   'a:tc': {
         '@gridSpan': options.gridSpan || '1',
         '@hMerge': options.hMerge ? options.hMerge : '0',
         '@rowSpan': options.rowSpan || '1',
         '@vMerge': options.vMerge ? options.vMerge : '0',
...

With this you can add new options to cell:

// Merge Rows
let cell_opts = {font_size: fontSize, font_face: 'Arial', rowSpan=<n>}; // first cell to merge vertically
let cell_opts = {font_size: fontSize, font_face: 'Arial', vMerge="1"}; // next cells

// Merge Columns
let cell_opts = {font_size: fontSize, font_face: 'Arial', gridSpan=<n>}; // first cell to merge horizontally
let cell_opts = {font_size: fontSize, font_face: 'Arial', hMerge="1"}; // next cells

CristobalBL avatar Nov 07 '19 20:11 CristobalBL

@CristobalBL thank you

18876293672 avatar Dec 24 '19 01:12 18876293672

for Word table, this is the pr and a small example. #348

Rackar avatar Apr 03 '20 16:04 Rackar

as @Rackar wrote pr link, my example based on it

const table = [];
const row1 = [
      {val: 'test 1', opts: {vMerge: 'restart'}},
      {val: 'test 2'},
      {val: 'test 3'},
    ];
    const row2 = [
      {opts: {vMerge: 'continue'}},
      {val: 'test 5'},
      {val: 'test 6'},
    ];
table.push(row1);
table.push(row2);
docx.createTable(table);
----------------------------
| test 1 | test 2 | test 3 |
|        |--------|--------|
|        | test 5 | test 6 |
----------------------------

iamsimakov avatar Jun 04 '20 11:06 iamsimakov