@silencesys/xlsx-to-xml
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10538
6
191