OfficeGen how to set table data text size?

Viewed 736

I am using officeGen to generate word documents.

generateDocumentService.js

var generateReportFromTableData = function (tableData) {
  console.log('tableData: ', tableData);
 var docx = officegen({
    type: 'docx',
    orientation: 'portrait',
    pageMargins: {
      top: 1000,
      left: 1000,
      bottom: 1000,
      right: 1000
    }
  })
  docx.on('error', function (err) {
    console.log(err)
  })
  pObj = docx.createP({
    align: 'center'
  })

  pObj.addText('Business Process General Information', {
    border: 'dotted',
    borderSize: 12,
    borderColor: '88CCFF',
    bold: true
  })
  var table = [
    [
    {
      val: 'Ref',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Risk Statements',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Max Impact',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Control effectiveness',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Recommended Risk Rating',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Frequency',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Impact',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Validated Review Risk Rating',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '10',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    {
      val: 'Rational For Risk Adjustment',
      opts: {
        cellColWidth: 2000,
        b: true,
        sz: '20',
        shd: {
          fill: '7F7F7F',
          themeFill: 'Arial',
          themeFillTint: '20'
        },
        fontFamily: 'Arial'
      }
    },
    ],
    ['Ahmed', 'Ghrib', 'Always', 'Finds','A','Soulution', 'Finds','A','Soulution'],
    ['Ahmed', 'Ghrib', 'Always', 'Finds','A','Soulution', 'Finds','A','Soulution'],
    ['Ahmed', 'Ghrib', 'Always', 'Finds','A','Soulution', 'Finds','A','Soulution'],
    ['Ahmed', 'Ghrib', 'Always', 'Finds','A','Soulution', 'Finds','A','Soulution'],
    ['Ahmed', 'Ghrib', 'Always', 'Finds','A','Soulution', 'Finds','A','Soulution'],
    ['Ahmed', 'Ghrib', 'Always', 'Finds','A','Soulution', 'Finds','A','Soulution'],
  ]

  var tableStyle = {
    tableColWidth: 4261,
    tableSize: 72,
    tableColor: 'ada',
    tableAlign: 'left',
    tableFontFamily: 'Comic Sans MS',
    borders: true
  }
  pObj = docx.createTable(table, tableStyle)
  var out = fs.createWriteStream(path.join('./docs/Table Data Report.docx'))

  out.on('error', function (err) {
    console.log(err)
  })

  async.parallel(
    [
      function (done) {
        out.on('close', function () {
          console.log('Finish to create a DOCX file.')
          done(null)
        })
        docx.generate(out)
      }
    ],
    function (err) {
      if (err) {
        console.log('error: ' + err)
      } // Endif.
    }
  )
}  

Here's the result :
enter image description here

Although I really love the OfficeGen framework, I couldn't find a way to choose a size for the text inside the table. It seems that either they have missed it or I couldn't find how.
For the table column headers it was possible with this property sz inside their definition:

{val: 'Ref',
  opts: {
    cellColWidth: 2000,
    b: true,
    sz: '10',
    shd: {
      fill: '7F7F7F',
      themeFill: 'Arial',
      themeFillTint: '20'
    },
    fontFamily: 'Arial'
  }
}

But for the data inside the table, for days I couldn't find a way. Nothing inside the tableStyle definition hints to a way to do that:

  var tableStyle = {
    tableColWidth: 4261,
    tableSize: 72,
    tableColor: 'ada',
    tableAlign: 'left',
    tableFontFamily: 'Comic Sans MS',
    borders: true
  }

Any help?? Thanks!
Generating word document with OfficeGen documentation

2 Answers

You can try out with below code in your configuration

var tableStyle = {
    sz: 20
    tableColWidth: 4261,
    tableSize: 72,
    tableColor: 'ada',
    tableAlign: 'left',
    tableFontFamily: 'Comic Sans MS',
    borders: true
  }

sz: 20 - this value will divide by 2 and it sets the font size ie. if you want to set size as 10 you have to set configuration as 20)

Mark this as answer . Thumps up if this works for you !!!!

I have done this using only 'column headers' for multiple rows in the table

Related