Sunday, 7 May 2017

Protractor : xlsx-template Error cannot read property 'length' of undefined

I am using xlsx-template to generate Excel files on the base of custom template that I have created. But I am getting error while creating a new excel file out of template

Below is the error :

E/launcher - Cannot read property 'length' of undefined E/launcher - TypeError: Cannot read property 'length' of undefined at Workbook.module.exports.Workbook.loadSheet (E:\latest-code\latest\test automation\node_modules\xlsx-template\lib\index.js:373:38) at Workbook.module.exports.Workbook.substitute (E:\latest-code\latest\test automation\node_modules\xlsx-template\lib\index.js:123:26) at E:\latest-code\latest\test automation\config\index.js:117:16 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:416:3)

Code Snippet:

 var XlsxTemplate = require('xlsx-template'),
      fs = require('fs'),
      path = require('path');

        describe("excel", function() {

          it("excel file", function() {
            console.log('inside after each...');
            console.log(__dirname);
            fs.readFile(path.join(__dirname, 'Template.xlsx'), function(err, data) {

              var template = new XlsxTemplate(data);
              var values = {
                testcase: [{
                  id: 1,
                  name: "login",
                  status: "pass"
                }, {
                  id: 2,
                  name: "logout",
                  status: "fail"
                }, {
                  id: 3,
                  name: "searchbox",
                  status: "pass"
                }]
              }
              console.log(values);
              template.substitute(1, values);

              console.log('excel data');

              var newData = template.generate();

              fs.writeFileSync('test1.xlsx', newData, 'binary');
            });
          })

Am I missing any other configuration for xlsx-template. Please advice how to get rid of this error as I am not able to resolve it.

Thanks in advance.



via prpa1234

No comments:

Post a Comment