{"id":17704984,"url":"https://github.com/dwqs/js2excel","last_synced_at":"2025-10-22T18:27:21.517Z","repository":{"id":57283921,"uuid":"95939247","full_name":"dwqs/js2excel","owner":"dwqs","description":":relieved: :smiley: :imp: A simple module for excel and json converts each other, which works in the browser.","archived":false,"fork":false,"pushed_at":"2023-08-24T19:32:01.000Z","size":1666,"stargazers_count":99,"open_issues_count":12,"forks_count":23,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-07T20:09:44.526Z","etag":null,"topics":["excel","js","json","xlsx"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwqs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-07-01T03:19:42.000Z","updated_at":"2023-12-13T06:15:34.000Z","dependencies_parsed_at":"2022-08-31T00:00:21.193Z","dependency_job_id":"5eb20301-70dc-4451-ae65-c3fa8853ed1e","html_url":"https://github.com/dwqs/js2excel","commit_stats":{"total_commits":91,"total_committers":3,"mean_commits":"30.333333333333332","dds":"0.10989010989010994","last_synced_commit":"c11bb0ffeb2972f7382348b226052abed4ef703e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fjs2excel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fjs2excel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fjs2excel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fjs2excel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwqs","download_url":"https://codeload.github.com/dwqs/js2excel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233994625,"owners_count":18762876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["excel","js","json","xlsx"],"created_at":"2024-10-24T22:05:45.379Z","updated_at":"2025-09-23T19:30:57.867Z","avatar_url":"https://github.com/dwqs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![download](https://img.shields.io/npm/dt/js2excel.svg) ![npm-version](https://img.shields.io/npm/v/js2excel.svg) ![license](https://img.shields.io/npm/l/js2excel.svg) ![bower-license](https://img.shields.io/bower/l/js2excel.svg)\n\n## js2excel\nA simple module for excel and json converts each other.\n\n## Installation\n\nIt is recommended to run webpack on node 6.x or higher.\n\nInstall the pkg with npm:\n\n```\nnpm install js2excel --save\n```\n\nor yarn\n\n```\nyarn add js2excel\n```\n\nor bower\n\n```\nbower install js2excel\n```\n\n## Usage\n\n### Convert json to excel\n```\n// es6\nimport {json2excel, excel2json} from 'js2excel';\n\n//CommonJS\nlet { json2excel, excel2json } = require('js2excel');\n\n// excel's data will be exports, which you probably get it from server.\nlet data = [\n    {\n        \"userId\": 1,\n        \"userPhoneNumber\": 1888888888,\n        \"userAddress\": 'xxxx',\n        \"date\": '2013/09/10 09:10'  // string\n    },\n    {\n        \"userId\": 2,\n        \"userPhoneNumber\": 1888888888,\n        \"userAddress\": 'xxxx',\n        \"date\": new Date()\n    },\n    {\n        \"userId\": 3,\n        \"userPhoneNumber\": 1888888888,\n        \"userAddress\": 'xxxx',\n        \"date\": new Date()\n    }\n];\n\n// this will be export a excel and the file's name is user-info-data.xlsx\n// the default file's name is excel.xlsx\ntry {\n    json2excel({\n        data,\n        name: 'user-info-data',\n        formateDate: 'yyyy/mm/dd'\n    });\n} catch (e) {\n    console.error('export error');\n}\n\n// for webpack 3: dynamic import\nimport(/* webpackChunkName: \"js2excel\" */ 'js2excel').then(({json2excel}) =\u003e {\n    json2excel({\n        data,\n        name: 'test',\n        formateDate: 'dd/mm/yyyy'\n    });\n}).catch((e) =\u003e {\n\n});\n```\nExports result as the image shows:\n\n![test-data](https://sfault-image.b0.upaiyun.com/148/574/1485742647-5961130140811_articlex)\n\n### Convert excel(.numbers/.xlsx/.xls) to json\n```\nimport { excel2json } from 'js2excel';\n\n// html\n\u003cinput type=\"file\" multiple=\"false\" id=\"sheets\" accept=\"application/x-iwork-keynote-sffnumbers,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\" @change=\"onchange\" /\u003e\n\n// methods\nonchange(e){\n    excel2json(e.target.files, (data) =\u003e {\n        console.log('json', data)\n    }, 'excel2json')\n}\n\n// for webpack 3: dynamic import\nonchange(e) {\n    import(/* webpackChunkName: \"js2excel\" */ 'js2excel').then(({excel2json}) =\u003e {\n        excel2json(e.target.files, (data) =\u003e {\n            console.log('json', data)\n        }, 'excel2json')\n    }).catch((e) =\u003e {\n\n    });\n}\n```\nExample, if you hava a excel as following:\n\n![excel](https://sfault-image.b0.upaiyun.com/411/420/4114209136-5960fa90e8e6d_articlex)\n\nThe data maybe as following:\n\n![data](https://sfault-image.b0.upaiyun.com/314/083/3140838997-5960fabf7c7b0_articlex)\n\n## API\n\n### json2excel(opts)\nConvert json to excel(.xlsx).\n\n**opts**\nType: `Object`\n\n`opts.data`\n\nType: `Array`\u003cbr/\u003e\nDefault: `[]`\n\nExcel's  data.\n\n`opts.name`\n\nType: `String`\u003cbr/\u003e\nDefault: `excel`\n\nExcel's name, whose suffix is `.xlsx`.\n\n`opts.formateDate`\n\nType: `String` \u003cbr/\u003e\nDefault: `dd/mm/yyyy`\n\nThe date formate in rows' data. Examples:\n\n```\n'dd/mm/yyyy' =\u003e 08/07/2017\n'd/m/yy' =\u003e 8/7/17\n'd/m/yy hh:ss' =\u003e 8/7/17 18:29\n'yyyy/mm/dd hh:ss' =\u003e 2017/07/17 18:29\n```\n\n### excel2json(files, cb(data), [defval])\nConvert excel(.numbers/.xlsx/.xls) to json.\n\n**files**\n\nType: `Array`\n\n[FileList](https://developer.mozilla.org/en-US/docs/Web/API/FileList) from `\u003cinput type='file' multiple=\"false\" \u003e`.\n\n**cb(data)**\n\nType: `Function`\n\nCallback function called on finish. The `data` maybe as following:\n\n```\n{   \n    `${sheetName}`: `[${excelRowsData}]`\n    'sheet1': [/** excel rows' data **/],\n    'sheet2': [/** excel rows' data **/],\n    'sheet3': [/** excel rows' data **/]\n    ...\n}\n```\n\n**defval**\n\nType: `String`\u003cbr/\u003e\nDefault: `''`\n\nThe default value when the row data corresponding to the column is blank.\n\n### csv2json(files, cb(data), [encode])\nConvert CSV file to json.\n\n**files**\n\nType: `Array`\n\n[FileList](https://developer.mozilla.org/en-US/docs/Web/API/FileList) from `\u003cinput type='file' multiple=\"false\" \u003e`.\n\n**cb(data)**\n\nType: `Function`\n\nCallback function called on finish.\n\n**encode**\n\nType: `String`\u003cbr/\u003e\nDefault: `UTF-8`\n\nThe default encode when reading file.\n\n## Supported browsers\n* [FileSaver#supported-browsers](https://github.com/eligrey/FileSaver.js#supported-browsers)\n* [FileReader](https://caniuse.com/#search=FileReader)\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwqs%2Fjs2excel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwqs%2Fjs2excel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwqs%2Fjs2excel/lists"}