@jsreport/jsreport-xlsx
Advanced tools
Comparing version 4.0.2 to 4.1.0
const { col2num } = require('xlsx-coordinates') | ||
const CELL_REG_REGEXP = /^(?:('?(?:\[([A-Za-z0-9_. ]+\.xlsx)\])?([A-Za-z0-9_. ]+)'?)!)?(\$?[A-Z]+)(\$?\d+)$/ | ||
// allows to parse cell expressions like: | ||
@@ -10,5 +12,7 @@ // - B6, $B6 (locked column), B$6 (locked row), $B$6 (locked column and row) | ||
// result: <complete ref from left>:<complete ref from right> | ||
// it is returned from a fn because it needs to use the global flag on regexp, | ||
// and we can not reuse the same regexp instance safely, it needs to be a new one for execution | ||
const getRangeOrMultiCellRefExpressionRegexp = () => /((?:'?(?:\[(?:[A-Za-z0-9_. ]+\.xlsx)\])?(?:[A-Za-z0-9_. ]+)'?!)?(?:\$?[A-Z]+\$?\d+:))?((?:'?(?:\[(?:[A-Za-z0-9_. ]+\.xlsx)\])?(?:[A-Za-z0-9_. ]+)'?!)?(?:\$?[A-Z]+\$?\d+))/g | ||
function parseCellRef (cellRef, startCellRef) { | ||
function parseCellRef (cellRef, parsedStartCellRef) { | ||
// parses single cell ref like: | ||
@@ -18,4 +22,3 @@ // B6, $B6 (locked column), B$6 (locked row), $B$6 (locked column and row) | ||
// [WorkbookName.xlsx]SheetName!B6, '[WorkbookName.xlsx]SheetName'!B6 (workbook name reference) and variants with locked columns and rows | ||
const cellRefRegexp = /^(?:('?(?:\[([A-Za-z0-9_. ]+\.xlsx)\])?([A-Za-z0-9_. ]+)'?)!)?(\$?[A-Z]+)(\$?\d+)$/ | ||
const matches = cellRef.match(cellRefRegexp) | ||
const matches = cellRef.match(CELL_REG_REGEXP) | ||
@@ -46,6 +49,6 @@ if (matches == null || matches[4] == null) { | ||
if (matches[3] == null && startCellRef != null) { | ||
workbookName = startCellRef.workbookName | ||
sheetName = startCellRef.sheetName | ||
sensitiveName = startCellRef.sensitiveName | ||
if (matches[3] == null && parsedStartCellRef != null) { | ||
workbookName = parsedStartCellRef.workbookName | ||
sheetName = parsedStartCellRef.sheetName | ||
sensitiveName = parsedStartCellRef.sensitiveName | ||
} | ||
@@ -52,0 +55,0 @@ |
@@ -29,3 +29,3 @@ | ||
if (concatenating) { | ||
if (elements[i].parentNode.previousSibling.localName === 'r') { | ||
if (elements[i].parentNode.previousSibling?.localName === 'r') { | ||
validSiblings = elements[i].parentNode.previousSibling === elements[i - 1].parentNode | ||
@@ -32,0 +32,0 @@ } else { |
@@ -170,3 +170,6 @@ const path = require('path') | ||
if (tEls[0].textContent.endsWith(':')) { | ||
if (tEls.length === 1) { | ||
const expectedRegexp = /^{{xlsxColAutofit( [^}]*)?}}$/ | ||
shouldRemoveComment = expectedRegexp.test(tEls[0].textContent) | ||
} else if (tEls[0].textContent.endsWith(':')) { | ||
const remainingText = tEls.slice(1).map((el) => el.textContent).join('') | ||
@@ -681,6 +684,6 @@ const expectedRegexp = /^\r?\n?{{xlsxColAutofit( [^}]*)?}}$/ | ||
formulaEl.textContent = `{{xlsxSData type='formula' originalCellRef='${cellRef}' originalFormula='${formula}'` | ||
formulaEl.textContent = `{{xlsxSData type='formula' originalCellRef='${cellRef}' originalFormula='${jsSingleQuoteEscape(formula)}'` | ||
if (sharedFormula?.type === 'source') { | ||
formulaEl.setAttribute('ref', `{{xlsxSData type='formulaSharedRefRange' originalSharedRefRange='${sharedFormula.sourceRef}'}}`) | ||
formulaEl.setAttribute('ref', `{{xlsxSData type='formulaSharedRefRange' originalSharedRefRange='${jsSingleQuoteEscape(sharedFormula.sourceRef)}'}}`) | ||
} | ||
@@ -1294,1 +1297,13 @@ | ||
} | ||
function jsSingleQuoteEscape (string) { | ||
return ('' + string).replace(/[']/g, function (character) { | ||
// Escape all characters not included in SingleStringCharacters and | ||
// DoubleStringCharacters on | ||
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4 | ||
switch (character) { | ||
case "'": | ||
return '\\' + character | ||
} | ||
}) | ||
} |
@@ -12,3 +12,3 @@ const { response } = require('@jsreport/office') | ||
res.content = xlsxOutputPath | ||
await res.output.update(Buffer.from(xlsxOutputPath)) | ||
@@ -15,0 +15,0 @@ xlsxOutputPath = await transform(reporter, definition, req, res) |
@@ -13,3 +13,4 @@ const fs = require('fs') | ||
const xlsxOutputContent = await fs.promises.readFile(res.content) | ||
const resContent = await res.output.getBuffer() | ||
const xlsxOutputContent = await fs.promises.readFile(resContent) | ||
req.data.$xlsxTemplate = await parseXlsx(xlsxOutputContent) | ||
@@ -20,2 +21,3 @@ | ||
req.context.asyncHandlebars = true | ||
const contentString = await reporter.templatingEngines.evaluate({ | ||
@@ -30,10 +32,17 @@ engine: req.template.engine, | ||
}, req) | ||
req.context.asyncHandlebars = false | ||
// we need to call afterTemplatingEnginesExecutedListeners to ensure the assets are extracted | ||
const fakeRes = { content: Buffer.from(contentString) } | ||
const fakeRes = reporter.Response(`xlsx-transformation-${req.context.id}`) | ||
await fakeRes.output.update(Buffer.from(contentString)) | ||
await reporter.afterTemplatingEnginesExecutedListeners.fire(req, fakeRes) | ||
let content | ||
try { | ||
content = JSON.parse(fakeRes.content.toString()) | ||
content = (await fakeRes.output.getBuffer()).toString() | ||
content = JSON.parse(content) | ||
} catch (e) { | ||
@@ -40,0 +49,0 @@ throw reporter.createError('Error parsing xlsx content, aren\'t you missing {{{xlsxPrint}}}?', { |
{ | ||
"name": "@jsreport/jsreport-xlsx", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": "jsreport recipe rendering excels directly from open xml", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@jsreport/office": "4.0.0", | ||
"@jsreport/office": "4.1.0", | ||
"@xmldom/xmldom": "0.8.6", | ||
@@ -50,6 +50,6 @@ "html-entities": "2.4.0", | ||
"devDependencies": { | ||
"@jsreport/jsreport-assets": "4.0.2", | ||
"@jsreport/jsreport-assets": "4.1.0", | ||
"@jsreport/jsreport-components": "4.0.0", | ||
"@jsreport/jsreport-core": "4.1.0", | ||
"@jsreport/jsreport-data": "4.0.0", | ||
"@jsreport/jsreport-core": "4.2.0", | ||
"@jsreport/jsreport-data": "4.1.0", | ||
"@jsreport/jsreport-handlebars": "4.0.1", | ||
@@ -56,0 +56,0 @@ "@jsreport/jsreport-jsrender": "4.0.0", |
@@ -10,2 +10,10 @@ # @jsreport/jsreport-xlsx | ||
### 4.1.0 | ||
- performance optimizations | ||
- remove the xlsxColAutofit comment also if there is no more text in the comment | ||
- fix concat tags logic in some cases | ||
- internal changes to support new `response.output` api | ||
- fix xlsx with formulas stored with `'` string delimiters | ||
### 4.0.2 | ||
@@ -12,0 +20,0 @@ |
@@ -549,3 +549,5 @@ /* eslint no-unused-vars: 0 */ | ||
return optionsToUse.fn(this, { data: newData }) | ||
const result = optionsToUse.fn(this, { data: newData }) | ||
return result | ||
} | ||
@@ -552,0 +554,0 @@ |
242758
5218
81
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@jsreport/office@4.1.0(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedarchiver@7.0.1(transitive)
+ Addedarchiver-utils@5.0.2(transitive)
+ Addedaxios@1.6.7(transitive)
+ Addedb4a@1.6.7(transitive)
+ Addedbare-events@2.5.4(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedbuffer-crc32@1.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcompress-commons@6.0.2(transitive)
+ Addedcrc32-stream@6.0.0(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedfast-fifo@1.3.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedqueue-tick@1.0.1(transitive)
+ Addedreadable-stream@4.7.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstreamx@2.21.1(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedtar-stream@3.1.7(transitive)
+ Addedtext-decoder@1.2.3(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
+ Addedzip-stream@6.0.1(transitive)
- Removed@jsreport/office@4.0.0(transitive)
- Removedarchiver@5.3.0(transitive)
- Removedarchiver-utils@2.1.03.0.4(transitive)
- Removedaxios@1.6.2(transitive)
- Removedbl@4.1.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedcompress-commons@4.1.2(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcrc32-stream@4.0.3(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedlodash.defaults@4.2.0(transitive)
- Removedlodash.difference@4.5.0(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedlodash.isplainobject@4.0.6(transitive)
- Removedlodash.union@4.6.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedtar-stream@2.2.0(transitive)
- Removedzip-stream@4.1.1(transitive)
Updated@jsreport/office@4.1.0