xlsx-template-browser 0.1.6 → 0.1.8

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.
@@ -27,7 +27,7 @@ const dateToExcel = (value) => {
27
27
  * or undefined if the data type is not recognized.
28
28
  */
29
29
  export const guessDataType = (value) => {
30
- if (typeof value === 'undefined') return undefined
30
+ if (typeof value === 'undefined') return { cellType: 's', value: '' }
31
31
  if (typeof value === 'number') {
32
32
  if (isFinite(value)) return { cellType: 'n', value }
33
33
  return undefined
@@ -69,6 +69,13 @@ export const createCell = ({ value, row, column, template, cellType }) => {
69
69
  if (!cellType && !value) {
70
70
  return template
71
71
  }
72
+ // If the cell is formula, then skip
73
+ if (cellType === 'f') {
74
+ // Check precalculated value
75
+ const v = value.querySelector('v')
76
+ if (v) v.remove()
77
+ return value
78
+ }
72
79
  // Clone initial node with the style or create a new one
73
80
  const cell = template ? template.cloneNode() : document.createElement('c')
74
81
  // Create a cell reference
package/lib/helpers.js CHANGED
@@ -57,6 +57,7 @@ export const getByNotation = (obj, props) => {
57
57
  let accessors = props.match(notationRegex)
58
58
  if (!accessors.length) return obj
59
59
  accessors = accessors.map(el => /^\d+$/.test(el) ? parseInt(el) : el)
60
- return getDeep(obj, accessors)
60
+ const value = getDeep(obj, accessors)
61
+ return value || ''
61
62
  }
62
63
 
package/lib/main.js CHANGED
@@ -80,7 +80,7 @@ const replace = async (template, data) => {
80
80
  // If we have table values, we need to process them in a separate way
81
81
  const isTable = typeof table === 'string'
82
82
  let value = getByNotation(data, accessor)
83
- if (!value) return false
83
+ if (typeof value === 'undefined') return false
84
84
  // Save tables for further processing
85
85
  if (isTable) {
86
86
  valuesToReplace[i] = { isTable, value: value.map(guessDataType) }
@@ -136,9 +136,17 @@ const replace = async (template, data) => {
136
136
  let newIndex = index + cellOffset
137
137
  // Get the cell value tag
138
138
  let v = c.querySelector('v') || {}
139
+ // Check if the cell contains formula, and skip
140
+ let isFormula = c.querySelector('f')
141
+ if (isFormula) {
142
+ const value = c
143
+ const cellType = 'f'
144
+ newCells[newIndex] = Object.assign({}, { value, cellType }, { template: c })
145
+ return false
146
+ }
139
147
  // Check if the cell contains string
140
- let f = c.getAttribute('t')
141
- if (!f || f !== 's') {
148
+ let isString = c.getAttribute('t')
149
+ if (!isString || isString !== 's') {
142
150
  newCells[newIndex] = Object.assign({}, { template: c })
143
151
  return false
144
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xlsx-template-browser",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "On-the-fly generation of .xlsx (Excel) files directly within the browser using templates constructed in Excel.",
5
5
  "main": "./lib/index",
6
6
  "files": [