Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jsreport/jsreport-xlsx

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsreport/jsreport-xlsx - npm Package Compare versions

Comparing version 3.2.3 to 3.3.0

2

lib/generation/index.js

@@ -22,3 +22,3 @@ const path = require('path')

templateAsset = templateAsset || {}
templateAsset.content = Buffer.from(req.template.xlsx.templateAsset.content, req.template.xlsx.templateAsset.encoding || 'utf8')
templateAsset.content = Buffer.from(req.template.xlsx.templateAsset.content, req.template.xlsx.templateAsset.encoding || 'base64')
} else if (req.template.xlsx && req.template.xlsx.templateAssetShortid) {

@@ -25,0 +25,0 @@ const assetFound = await reporter.documentStore.collection('assets').findOne({ shortid: req.template.xlsx.templateAssetShortid }, req)

@@ -7,3 +7,3 @@ const path = require('path')

const toExcelDate = require('js-excel-date-convert').toExcelDate
const { serializeXml, nodeListToArray } = require('../../utils')
const { serializeXml, nodeListToArray, findOrCreateChildNode, findChildNode } = require('../../utils')
const defaultNewSheetContentPath = path.join(__dirname, '../../../static/defaultNewSheet.xml')

@@ -1015,36 +1015,2 @@ const defaultNewSheetContent = fs.readFileSync(defaultNewSheetContentPath, 'utf8')

function findOrCreateChildNode (docNode, nodeName, targetNode) {
let result
const existingNode = findChildNode(nodeName, targetNode)
if (!existingNode) {
result = docNode.createElement(nodeName)
targetNode.appendChild(result)
} else {
result = existingNode
}
return result
}
function findChildNode (nodeName, targetNode, allNodes = false) {
const result = []
for (let i = 0; i < targetNode.childNodes.length; i++) {
let found = false
const childNode = targetNode.childNodes[i]
if (childNode.nodeName === nodeName) {
found = true
result.push(childNode)
}
if (found && !allNodes) {
break
}
}
return allNodes ? result : result[0]
}
function removeChildNodes (nodeName, targetNode) {

@@ -1051,0 +1017,0 @@ for (let i = 0; i < targetNode.childNodes.length; i++) {

const path = require('path')
const { nodeListToArray } = require('../../utils')
const { nodeListToArray, findChildNode } = require('../../utils')

@@ -114,2 +114,51 @@ module.exports = function processChart (files, sheetContent, drawingEl) {

// ensuring the cached strings in xlsx are not processed by handlebars, because it will
// give errors otherwise
if (graphicDataChartEl.prefix === 'c') {
// it seems only the standard charts "c:" cache data in the chart definition,
// for the chartex it is not needed that we do something
const existingChartSeriesElements = nodeListToArray(chartDoc.getElementsByTagName('c:ser'))
for (const chartSerieEl of existingChartSeriesElements) {
const tagsToCheck = ['c:tx', 'c:cat', 'c:val', 'c:xVal', 'c:yVal', 'c:bubbleSize']
for (const targetTag of tagsToCheck) {
const existingTagEl = findChildNode(targetTag, chartSerieEl)
if (existingTagEl == null) {
continue
}
const strRefEl = findChildNode('c:strRef', existingTagEl)
const numRefEl = findChildNode('c:numRef', existingTagEl)
for (const targetInfo of [{ el: strRefEl, cacheTag: 'strCache' }, { el: numRefEl, cacheTag: 'numCache' }]) {
if (targetInfo.el == null) {
continue
}
const cacheEl = findChildNode(`c:${targetInfo.cacheTag}`, targetInfo.el)
if (cacheEl == null) {
continue
}
const ptEls = findChildNode('c:pt', cacheEl, true)
for (const ptEl of ptEls) {
const ptValueEl = findChildNode('c:v', ptEl)
if (ptValueEl == null) {
continue
}
if (ptValueEl.textContent.includes('{{') && ptValueEl.textContent.includes('}}')) {
ptValueEl.textContent = `{{{{xlsxSData type='raw'}}}}${ptValueEl.textContent}{{{{/xlsxSData}}}}`
}
}
}
}
}
}
const chartTitles = nodeListToArray(chartEl.getElementsByTagName(`${graphicDataChartEl.prefix}:title`))

@@ -116,0 +165,0 @@ const chartMainTitleEl = chartTitles[0]

@@ -12,3 +12,10 @@ const { DOMParser, XMLSerializer } = require('@xmldom/xmldom')

try {
const files = await decompress()(xlsxTemplateContent)
let files
try {
files = await decompress()(xlsxTemplateContent)
} catch (parseTemplateError) {
throw reporter.createError('Failed to parse xlsx template input', {
original: parseTemplateError
})
}

@@ -15,0 +22,0 @@ for (const f of files) {

@@ -9,2 +9,3 @@ const fs = require('fs')

const $xlsxOriginalContent = req.data.$xlsxOriginalContent || ''
if ($xlsxOriginalContent.trim() !== '') {

@@ -11,0 +12,0 @@ const transform = require('./transformation')

@@ -77,2 +77,36 @@ const path = require('path')

function findOrCreateChildNode (docNode, nodeName, targetNode) {
let result
const existingNode = findChildNode(nodeName, targetNode)
if (!existingNode) {
result = docNode.createElement(nodeName)
targetNode.appendChild(result)
} else {
result = existingNode
}
return result
}
function findChildNode (nodeName, targetNode, allNodes = false) {
const result = []
for (let i = 0; i < targetNode.childNodes.length; i++) {
let found = false
const childNode = targetNode.childNodes[i]
if (childNode.nodeName === nodeName) {
found = true
result.push(childNode)
}
if (found && !allNodes) {
break
}
}
return allNodes ? result : result[0]
}
function getChartEl (drawingEl) {

@@ -176,2 +210,4 @@ let parentEl = drawingEl.parentNode

module.exports.getChartEl = getChartEl
module.exports.findOrCreateChildNode = findOrCreateChildNode
module.exports.findChildNode = findChildNode
module.exports.nodeListToArray = nodeListToArray

@@ -178,0 +214,0 @@ module.exports.isWorksheetFile = isWorksheetFile

{
"name": "@jsreport/jsreport-xlsx",
"version": "3.2.3",
"version": "3.3.0",
"description": "jsreport recipe rendering excels directly from open xml",

@@ -33,3 +33,3 @@ "keywords": [

"@jsreport/office": "3.0.0",
"@xmldom/xmldom": "0.7.0",
"@xmldom/xmldom": "0.8.6",
"js-excel-date-convert": "1.0.2",

@@ -50,5 +50,5 @@ "lodash": "4.17.21",

"devDependencies": {
"@jsreport/jsreport-assets": "3.4.4",
"@jsreport/jsreport-assets": "3.5.0",
"@jsreport/jsreport-components": "3.2.1",
"@jsreport/jsreport-core": "3.8.0",
"@jsreport/jsreport-core": "3.9.0",
"@jsreport/jsreport-data": "3.0.1",

@@ -55,0 +55,0 @@ "@jsreport/jsreport-handlebars": "3.2.1",

@@ -10,2 +10,7 @@ # @jsreport/jsreport-xlsx

### 3.3.0
- xlsxAddImage support for alt text
- fix xlsx chart generation when it points to dynamic table generated by loop
### 3.2.3

@@ -12,0 +17,0 @@

@@ -386,4 +386,15 @@ /* eslint no-unused-vars: 0 */

async function addImage (imageName, sheetFullName, fromCol, fromRow, toCol, toRow) {
async function addImage (imageNameOrOptions, sheetFullName, fromCol, fromRow, toCol, toRow) {
const { context, options } = contextMap.get(this)
let imageName
let imageAltText
if (typeof imageNameOrOptions === 'string') {
imageName = imageNameOrOptions
} else {
// imageNameOrOptions is expected to be object here
imageName = imageNameOrOptions.name
imageAltText = imageNameOrOptions.altText
}
const name = imageName + '.png'

@@ -432,3 +443,3 @@

toCol + '</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>' + toRow + '</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:to><xdr:pic><xdr:nvPicPr>' +
'<xdr:cNvPr id="' + relNumber + '" name="Picture"/><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr><xdr:blipFill>' +
`<xdr:cNvPr id="${relNumber}" name="Picture"${imageAltText != null && imageAltText !== '' ? ` descr="${imageAltText}"` : ''}/><xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr><xdr:blipFill>` +
'<a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="' + relName + '"><a:extLst>' +

@@ -435,0 +446,0 @@ '<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}"><a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" ' +

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc