xlsx-template-browser 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/excelHelpers.js +8 -1
- package/lib/main.js +11 -2
- package/package.json +1 -1
package/lib/excelHelpers.js
CHANGED
|
@@ -61,10 +61,17 @@ export const createSharedString = (text, template) => {
|
|
|
61
61
|
* @param {string|number} options.row - The row reference for the cell.
|
|
62
62
|
* @param {string|number} options.column - The column reference (either string or numeric) for the cell.
|
|
63
63
|
* @param {Element} options.template - (Optional) An existing template to clone for the cell.
|
|
64
|
-
* @param {string} options.cellType - The type of the cell (e.g., 's', 'n', 'b') for Excel formatting.
|
|
64
|
+
* @param {string} options.cellType - The type of the cell (e.g., 's', 'n', 'b', 'f') for Excel formatting.
|
|
65
65
|
* @returns {Element} - The created cell element.
|
|
66
66
|
*/
|
|
67
67
|
export const createCell = ({ value, row, column, template, cellType }) => {
|
|
68
|
+
// If the cell is formula, then skip
|
|
69
|
+
if (cellType === 'f') {
|
|
70
|
+
// Check precalculated value
|
|
71
|
+
const v = value.querySelector('v')
|
|
72
|
+
if (v) v.remove()
|
|
73
|
+
return value
|
|
74
|
+
}
|
|
68
75
|
// Clone initial node with the style or create a new one
|
|
69
76
|
const cell = template ? template.cloneNode() : document.createElement('c')
|
|
70
77
|
// Create a cell reference
|
package/lib/main.js
CHANGED
|
@@ -69,7 +69,8 @@ const replace = async (template, data) => {
|
|
|
69
69
|
let { accessor, table } = match.groups
|
|
70
70
|
// If we have table values, we need to process them in a separate way
|
|
71
71
|
const isTable = typeof table === 'string'
|
|
72
|
-
|
|
72
|
+
let value = getByNotation(data, accessor)
|
|
73
|
+
if (!value) return false
|
|
73
74
|
// Save tables for further processing
|
|
74
75
|
if (isTable) {
|
|
75
76
|
valuesToReplace[i] = { isTable, value: value.map(guessDataType) }
|
|
@@ -125,6 +126,14 @@ const replace = async (template, data) => {
|
|
|
125
126
|
let newIndex = index + cellOffset
|
|
126
127
|
// Get the cell value tag
|
|
127
128
|
let v = c.querySelector('v') || {}
|
|
129
|
+
// Check if the cell contains formula, and skip
|
|
130
|
+
let f = c.querySelector('f')
|
|
131
|
+
if (f) {
|
|
132
|
+
const value = c
|
|
133
|
+
const cellType = 'f'
|
|
134
|
+
newCells[newIndex] = Object.assign({}, { value, cellType }, { template: c })
|
|
135
|
+
return false
|
|
136
|
+
}
|
|
128
137
|
// Get the new value to replace
|
|
129
138
|
let newValue = valuesToReplace[v.textContent] || {}
|
|
130
139
|
if (!Array.isArray(newValue)) {
|
|
@@ -145,7 +154,7 @@ const replace = async (template, data) => {
|
|
|
145
154
|
}
|
|
146
155
|
// If the value is an array (not from table), then extend the existing list of cells
|
|
147
156
|
for (let i = 0; i < newValue.length; i++) {
|
|
148
|
-
let { value, cellType } = newValue[i]
|
|
157
|
+
let { value, cellType } = newValue[i] || {}
|
|
149
158
|
if (cellType === 's' && typeof value === 'string') value = addString(value)
|
|
150
159
|
newCells[newIndex + i] = Object.assign({}, { value, cellType }, { template: c })
|
|
151
160
|
if (i) cellOffset++
|
package/package.json
CHANGED