2.3.7 • Published 6 months ago

xlsx-populator v2.3.7

Weekly downloads
94
License
MIT
Repository
github
Last release
6 months ago

xlsx-populator

Library for populating xlsx templates with json data. Array values will be automatically cloned

Usage

  1. add this module as dependency for you project
  2. Use it, where you need

    const { xlsxPopulator } = require('xlsx-populator');

  3. Call xlsxPopulator with next arguments:

    • inputFilePath - relative, or absolute path to .docx file
    • outputFilePath - path, where populated .docx should appear
    • dataObj - JSON object with data
  4. Promise will be returned with path to generated file

Usage example:

const handleDocx = (data, cb) => {
  const operationId = new Date().getTime();

  console.log('operationId', operationId);

  const dataObj = data.data;
  const docsPath = '/docs/' + operationId;
  const dirPath = 'public' + docsPath;
  fs.mkdir(dirPath, () => {

    const filePath = dirPath + '/input.docx';
    const file = fs.createWriteStream(filePath);
    const getFunction = data.template.match(/^https/) ? https.get : http.get;
    const request = getFunction(data.template, function(response) {
      response.pipe(file);
      file.on('finish', function() {
        file.close(() => {

          return xlsxPopulator(
            filePath,
            path.join(__dirname,'../',dirPath , '/outputdocx.docx'),
            dataObj)
            .resolve(cb);
        });

      });
    }).on('error', function(err) {
      console.log('! fail to load file', err);

      if (cb) cb(err.message);
    });

  });
};
2.3.7

6 months ago

2.3.6

2 years ago

2.3.5

2 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.2.1

3 years ago

2.3.1

3 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago