Ziv-Barber / officegen

Standalone Office Open XML files (Microsoft Office 2007 and later) generator for Word (docx), PowerPoint (pptx) and Excell (xlsx) in javascript. The output is a stream.
MIT License
2.65k stars 471 forks source link

hi! could this can merge cells for table? #333

Open 18876293672 opened 4 years ago

18876293672 commented 4 years ago

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.

CristobalBL commented 4 years ago

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
18876293672 commented 4 years ago

@CristobalBL thank you

Rackar commented 4 years ago

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

iamsimakov commented 4 years ago

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 |
----------------------------