TypeError: carr[1].forEach is not a function #3102

Closed
opened 2024-04-03 05:44:19 +00:00 by RockyScube · 3 comments

I've check the documentation:

previously it was working, now it is not.

xlsx version:
"xlsx": "^0.18.5"

below is my code snippet:
`
// import
import xlsx from 'xlsx'

// implementation
let worksheet = xlsx.utils.json_to_sheet(data)

  let workbook = xlsx.utils.book_new()

  xlsx.utils.book_append_sheet(workbook, worksheet, 'employee')

  xlsx.writeFileXLSX(workbook, 'file.xlsx')
  // xlsx.writeFile(workbook, filename) // tried this as well

`

stack trace:
TypeError: carr[1].forEach is not a function at server/node_modules/xlsx/xlsx.js:23544:14 at Array.forEach (<anonymous>) at write_zip_xlsx (server/node_modules/xlsx/xlsx.js:23543:14) at write_zip_typeXLSX (server/node_modules/xlsx/xlsx.js:23758:10) at writeSyncXLSX (server/node_modules/xlsx/xlsx.js:23847:9) at Object.writeFileSyncXLSX [as writeFileXLSX] (server/node_modules/xlsx/xlsx.js:23921:9)

I've check the documentation: previously it was working, now it is not. xlsx version: `"xlsx": "^0.18.5"` below is my code snippet: ` // import import xlsx from 'xlsx' // implementation let worksheet = xlsx.utils.json_to_sheet(data) let workbook = xlsx.utils.book_new() xlsx.utils.book_append_sheet(workbook, worksheet, 'employee') xlsx.writeFileXLSX(workbook, 'file.xlsx') // xlsx.writeFile(workbook, filename) // tried this as well ` stack trace: ` TypeError: carr[1].forEach is not a function at server/node_modules/xlsx/xlsx.js:23544:14 at Array.forEach (<anonymous>) at write_zip_xlsx (server/node_modules/xlsx/xlsx.js:23543:14) at write_zip_typeXLSX (server/node_modules/xlsx/xlsx.js:23758:10) at writeSyncXLSX (server/node_modules/xlsx/xlsx.js:23847:9) at Object.writeFileSyncXLSX [as writeFileXLSX] (server/node_modules/xlsx/xlsx.js:23921:9) `
Author

it was due to date time field, changed it to string, working fine now.

it was due to date time field, changed it to string, working fine now.
Owner

Can you share the data that was causing issues? You should be able to pass date objects:

let data = [
	{date: new Date()}
]

let worksheet = XLSX.utils.json_to_sheet(data)

let workbook = XLSX.utils.book_new()

XLSX.utils.book_append_sheet(workbook, worksheet, 'employee')

XLSX.writeFileXLSX(workbook, 'file.xlsx')

https://jsfiddle.net/e8ygdcp6/

Can you share the data that was causing issues? You should be able to pass date objects: ```js let data = [ {date: new Date()} ] let worksheet = XLSX.utils.json_to_sheet(data) let workbook = XLSX.utils.book_new() XLSX.utils.book_append_sheet(workbook, worksheet, 'employee') XLSX.writeFileXLSX(workbook, 'file.xlsx') ``` https://jsfiddle.net/e8ygdcp6/
Author

Can you share the data that was causing issues? You should be able to pass date objects:

let data = [
	{date: new Date()}
]

let worksheet = XLSX.utils.json_to_sheet(data)

let workbook = XLSX.utils.book_new()

XLSX.utils.book_append_sheet(workbook, worksheet, 'employee')

XLSX.writeFileXLSX(workbook, 'file.xlsx')

https://jsfiddle.net/e8ygdcp6/

I'm using Lucid ORM which provides DateTime Type, maybe converting it JSDate() will work

> Can you share the data that was causing issues? You should be able to pass date objects: > > ```js > let data = [ > {date: new Date()} > ] > > let worksheet = XLSX.utils.json_to_sheet(data) > > let workbook = XLSX.utils.book_new() > > XLSX.utils.book_append_sheet(workbook, worksheet, 'employee') > > XLSX.writeFileXLSX(workbook, 'file.xlsx') > ``` > > https://jsfiddle.net/e8ygdcp6/ I'm using Lucid ORM which provides DateTime Type, maybe converting it JSDate() will work
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3102
No description provided.