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

@silencesys/xlsx-to-xml

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@silencesys/xlsx-to-xml - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

40

lib/exporter.js

@@ -134,4 +134,19 @@ import xlsx from 'xlsx'

const checkNextRowForContent = (sheet, rowNum, cells = [0, 1], content = '', currentRow) => {
const emptyCell = sheet[xlsx.utils.encode_cell({ r: rowNum + 1, c: cells[0] })]
const contentCell = sheet[xlsx.utils.encode_cell({ r: rowNum + 1, c: cells[1] })]
if (!emptyCell &&contentCell) {
content = ` ${cleanAndFormatColumnValue(contentCell.h)}`
console.info(`${COLOR.fgYellow}[${rowNum + 2}]\t${COLOR.reset}Has one cell empty, the other cell: "${COLOR.fgBlue}${content}${COLOR.reset}" was appended to the row #${currentRow}`)
return checkNextRowForContent(sheet, rowNum + 1, cells, content, currentRow)
}
return content
}
// Read the input file
try {
console.info(`${COLOR.bgBlue}${COLOR.fgBlack}Starting exporting file: ${INPUT_FILE}${COLOR.reset}\n`)
const file = xlsx.readFile(INPUT_FILE)

@@ -147,20 +162,17 @@ const sheet = file.Sheets[file.SheetNames[0]]

if (firstCell && secondCell) {
const idFirstCell = `${firstCell.v.slice(0, 1).toUpperCase()}-0-${rowNum}`
const idSecondCell = `${firstCell.v.slice(0, 1).toUpperCase()}-1-${rowNum}`
const idFirstCell = `${firstCell.v.slice(0, 1).toUpperCase()}-0-${rowNum + 1}`
const idSecondCell = `${firstCell.v.slice(0, 1).toUpperCase()}-1-${rowNum + 1}`
let additionToSecondCell = ''
if (sheet[xlsx.utils.encode_cell({ r: rowNum + 1, c: 1 })]) {
const thirdCell = sheet[xlsx.utils.encode_cell({ r: rowNum + 1, c: 1 })]
if (thirdCell.v.length > 0) {
additionToSecondCell = cleanAndFormatColumnValue(thirdCell.h)
}
}
const additionToSecondCell = await checkNextRowForContent(sheet, rowNum, [0, 1], '', rowNum + 1)
const additionToFirstCell = await checkNextRowForContent(sheet, rowNum, [1, 0], '', rowNum + 1)
const firstColumnLanguage = CONFIG.language.length > 0 ? `xml:lang="${CONFIG.language[0]}"` : ''
const secondColumnLanguage = CONFIG.language.length > 1 ? `xml:lang="${CONFIG.language[1]}"` : ''
code.push(` <${CONFIG.rowTagName} id="${idFirstCell}" corresp="${idSecondCell}" ${firstColumnLanguage}>${cleanAndFormatColumnValue(firstCell.h)}</${CONFIG.rowTagName}>\n <${CONFIG.rowTagName} id="${idSecondCell}" corresp="${idFirstCell}" ${secondColumnLanguage}>${cleanAndFormatColumnValue(secondCell.h) + additionToSecondCell}</${CONFIG.rowTagName}>\n`)
code.push(` <${CONFIG.rowTagName} id="${idFirstCell}" corresp="${idSecondCell}" ${firstColumnLanguage}>${cleanAndFormatColumnValue(firstCell.h) + additionToFirstCell}</${CONFIG.rowTagName}>\n <${CONFIG.rowTagName} id="${idSecondCell}" corresp="${idFirstCell}" ${secondColumnLanguage}>${cleanAndFormatColumnValue(secondCell.h) + additionToSecondCell}</${CONFIG.rowTagName}>\n`)
} else if (secondCell) {
console.log(`${COLOR.fgYellow}Row ${rowNum + 1} has only one cell.${COLOR.reset}`)
console.log(`${COLOR.fgYellow}Cell content was merged with previous cell.${COLOR.reset}`)
// console.log(`${COLOR.dim}[${rowNum + 1}]\tSecond cell is empty.${COLOR.reset}`)
} else if (firstCell) {
// console.log(`${COLOR.dim}[${rowNum + 1}]\tFirst cell is empty.${COLOR.reset}`)
} else {
console.warn(`${COLOR.fgRed}Row ${rowNum + 1} is empty${COLOR.reset}`)
console.warn(`${COLOR.fgRed}[${rowNum + 1}]\tRow is empty${COLOR.reset}`)
}

@@ -177,3 +189,3 @@ }

fs.writeFileSync(OUTPUT_FILE, xml)
console.info(`${COLOR.bgGreen}${COLOR.fgBlack}Created ${OUTPUT_FILE}${COLOR.reset}`)
console.info(`\n${COLOR.bgGreen}${COLOR.fgBlack}Successfully created file: ${OUTPUT_FILE}${COLOR.reset}`)
exit(0)

@@ -180,0 +192,0 @@ } catch (err) {

{
"name": "@silencesys/xlsx-to-xml",
"version": "1.0.1",
"version": "1.0.2",
"description": "Export XLSX files to XML",

@@ -5,0 +5,0 @@ "main": "./lib/exporter.js",

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