'html-to-xlsx' generated excel file does not open



  • Hi,
    The excel file I generate with 'html-to-xlsx' recipe does not open and I don't know what am I doing wrong..
    (Works perfectly with phantompdf recipe)
    I tried to unzip generated xlsx and it looks correct (got all the folders and xml files the working xlsx zip has - didnt check internally line by line as i dont know the format)

    template:

    <table>
        <tr>
            <td style="height: 50px; font-size: 35px">Hello world</td>
            <td>world</td>
        </tr>
        <tr>
            <td style="width: 20px; text-align:right">right</td>
            <td>world</td>
        </tr>
        <tr>
            <td>world</td>
            <td>world</td>
        </tr>
    </table>
    
    

    server:

    // jsreport
    const jsreportcore = require('jsreport-core');
    const jsreporthandlebars = require('jsreport-handlebars');
    const jsreportphantompdf = require('jsreport-phantom-pdf');
    const jsreporthtmltoxlsx = require('jsreport-html-to-xlsx');
    const jsreportassets = require('jsreport-assets');
    exports.jsreport = jsreportcore({
      tasks: { strategy: 'in-process' },
      express: { app: app, server: server },
      appPath: "/report",
      rootDirectory: path.join(__dirname, './report_templates/piperings'),
      assets: {
        allowedFiles: "**",
        publicAccessEnabled: true,
        searchOnDiskIfNotFoundInStore: true,
      },
      phantom: {
        allowLocalFilesAccess: true
      },
      scripts: {
        allowedModules: "*"
      }
    });
    exports.jsreport.use(jsreporthandlebars());
    exports.jsreport.use(jsreportphantompdf());
    exports.jsreport.use(require('jsreport-xlsx')());
    exports.jsreport.use(jsreporthtmltoxlsx());
    exports.jsreport.use(jsreportassets({}));
    exports.jsreport.init().catch(e => console.log(e));
    

    Controller:

    var server = require('../../../server');
    exports.generateReportExcel = async function(req, res) {
    var data = await exports.loadSomeDataForExcelReport(req, res);
      server.jsreport.render({
        template: {
          recipe: 'html-to-xlsx',
          engine: 'handlebars',
          content: fs.readFileSync(path.join(__dirname, '..', '..', '..', './report_templates/piperings/piperingsExcel.hbs')).toString()
        },
        data: {}
        }).then((resp) => {
          // file created here doesnt open
          fs.writeFile(path.join(__dirname, "excelTest.xlsx"), resp.content, (err) => { });
          res.contentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
          res.send(resp.content);
        })
        .catch(err => {
          console.log('ERROR', err);
          res.end(err.message);
        });
    }
    

    My packagejson dependencies for jsreport:

        "express": "^4.16.3",
        "jsreport-assets": "^0.7.1",
        "jsreport-core": "^1.5.1",
        "jsreport-handlebars": "^1.1.2",
        "jsreport-html-to-xlsx": "^1.4.6",
        "jsreport-phantom-pdf": "^1.4.6",
        "jsreport-xlsx": "^1.4.2",
    

    (if i try with highest versions i got phantomjs errors)

    I did this with a help from example:
    https://github.com/carlaulloa/jsreport-nodejs-angular-example



  • This issue fixed itself after upgrading packeges to the newest versions (assets stopped working tho)
    "(if i try with highest versions i got phantomjs errors)"
    I fixed it by removing rootDirectory from jsreportcore


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.