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
Posts made by mapilat
-
RE: 'html-to-xlsx' generated excel file does not open
-
Can't add row to excel report with xlsx recipe
I cant add row with xlsx recipe. Changing sheet name seems to work fine tho
server.jsreport.render({ template: { recipe: 'xlsx', engine: 'handlebars', content: fs.readFileSync('./helloWorld.hbs').toString() } }, data: data }).then((resp) => { resp.stream.pipe(fs.createWriteStream(path.join(__dirname, "out.xlsx"))); res.contentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); res.send(resp.content); }) .catch(err => { console.log('ERROR', err); res.end(err.message); });
my helloWorld.hbs
{{#xlsxMerge "xl/workbook.xml" "workbook.sheets[0].sheet[0]"}} <sheet name="changing sheet name"/> {{/xlsxMerge}} {{#xlsxAdd "xl/worksheets/sheet1.xml" "worksheet.sheetData[0].row"}} <row> <c t="inlineStr"><is><t>Hello world</t></is></c> </row> {{/xlsxAdd}} {{{xlsxPrint}}}
-
Asset styles.css not found
Hi,
Got some problem with assets after upgrading every jsreport library to the newest version.
Can't generate my report with phantom-pdf recipe. I got an error:
Error: Asset styles.css not found
I use my style.css and and image file in my hbs template where i include {#asset} ... cant figure out what I might be missing..My template:
<style> {#asset styles.css @encoding=utf8} </style> <table cellpadding="0" cellspacing="0" style="width: 100%; padding:10px"> <tr> <td colspan="2"> <table> <tr> <td class="title"> <img src="{#asset logo.png @encoding=dataURI}" style="width:100%; max-width:300px;" /> </td> <td> Piperings report <br> Created: {{now}} </td> <td> Portfolio: {{portfolioCode}} <br> Module: {{moduleCode}} </td> </tr> </table> </td> </tr> </table>
Congfig:
exports.jsreport = jsreportcore({ tasks: { strategy: 'in-process' }, express: { app: app, server: server }, appPath: "/report", assets: { allowedFiles: "**", publicAccessEnabled: true, searchOnDiskIfNotFoundInStore: true, }, phantom: { allowLocalFilesAccess: false }, scripts: { allowedModules: "*" } });
Controller:
exports.generateReportPDF = async function(req, res) { var data = await exports.fetchSomeImportantData(req, res); var filePath = path.join(__dirname, "pdfTest.pdf"); generateReport(data, './report_templates/piperings/piperings.hbs', 'portrait', 'phantom-pdf') .then((resp) => { fs.writeFile(filePath, resp.content, function (err) { console.log("done"); }); res.contentType('application/pdf'); res.send(resp.content); }) .catch(err => { console.log('ERROR', err); //next(err); }); } function generateReport(data, filePath, orientation, recipe) { return server.jsreport.render({ template: { content: fs.readFileSync(path.join(__dirname, '..', '..', '..', filePath)).toString(), engine: 'handlebars', recipe: recipe, phantom: { orientation: orientation }, helpers: `function now() { return new Date().toLocaleDateString() }` + `function itemNo(index) { return index + 1; }` + `function getPageNumber(pages, pageIndex) { if (!pages || pageIndex == null) { return '' } const pagesToIgnore = pages.reduce((acu, page) => { const shouldIgnore = page.items.find((p) => p.ignorePageInCount === true) != null if (shouldIgnore) { acu.push(page) } return acu }, []).length const pageNumber = pageIndex + 1 return pageNumber - pagesToIgnore }` + `function getTotalPages(pages) { if (!pages) { return '' } const pagesToIgnore = pages.reduce((acu, page) => { const shouldIgnore = page.items.find((p) => p.ignorePageInCount === true) != null if (shouldIgnore) { acu.push(page) } return acu }, []).length return pages.length - pagesToIgnore }` }, data: data }); }
-
'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