{"id":21305565,"url":"https://github.com/tflanagan/js-spreadsheets","last_synced_at":"2025-03-15T19:28:03.449Z","repository":{"id":58237490,"uuid":"103396745","full_name":"tflanagan/js-spreadsheets","owner":"tflanagan","description":null,"archived":false,"fork":false,"pushed_at":"2021-11-23T16:02:45.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-21T19:08:05.047Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tflanagan.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}},"created_at":"2017-09-13T12:27:12.000Z","updated_at":"2021-11-23T16:02:48.000Z","dependencies_parsed_at":"2022-08-30T22:31:23.758Z","dependency_job_id":null,"html_url":"https://github.com/tflanagan/js-spreadsheets","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tflanagan%2Fjs-spreadsheets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tflanagan%2Fjs-spreadsheets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tflanagan%2Fjs-spreadsheets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tflanagan%2Fjs-spreadsheets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tflanagan","download_url":"https://codeload.github.com/tflanagan/js-spreadsheets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243780003,"owners_count":20346793,"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":[],"created_at":"2024-11-21T16:18:30.484Z","updated_at":"2025-03-15T19:28:03.422Z","avatar_url":"https://github.com/tflanagan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"spreadsheets\n============\n\n## Exports\n```javascript\nwindow.Spreadsheets = {\n\tCell: Cell,\n\tRow: Row,\n\tSheet: Sheet,\n\tparsers: {\n\t\tBaseParser: BaseParser,\n\t\tCSV: CSVParser,\n\t\tTSV: TSVParser\n\t},\n\twriters: {\n\t\tBaseWriter: BaseWriter,\n\t\tCSV: CSVWriter,\n\t\tTSV: TSVWriter\n\t}\n}\n```\n\n\n## Types\n```typescript\ntype FileObj = {\n\tfilename: string;\n\tdata: string | ArrayBuffer;\n};\n\ntype ProgressFn = (this: FileReader, event: ProgressEvent\u003cFileReader\u003e) =\u003e any;\n\nclass Cell {\n\tget: () =\u003e string;\n\tset: (contents: string) =\u003e Cell;\n}\nclass Row extends Array\u003cCell\u003e;\nclass Sheet extends Array\u003cRow\u003e;\n\nclass BaseParser {\n\tgetFile: () =\u003e FileObj;\n\tloadFile: (file: File, progress: ProgressFn) =\u003e Promise\u003cFileObj\u003e;\n\tsetContents: (contents: BlobPart, filename?: string, fileProps?: FilePropertyBag, progress?: ProgressFn) =\u003e Promise\u003cFileObj\u003e;\n}\n\nclass SVParser extends BaseParser {\n\tconstructor: (delimiter: string = ',') =\u003e SVParser;\n\tgetDelimiter: () =\u003e string;\n\tparseFile: () =\u003e Promise\u003cSheet\u003e;\n\tsetDelimiter: (delimiter: string): SVParser;\n}\n\nclass CSVParser extends SVParser {}\n\nclass TSVParser extends SVParser {}\n\nclass BaseWriter {\n\tconstructor: (type: string = 'text/plain', charset: string = 'utf-8') =\u003e BaseWriter;\n\taddSheet: (sheet?: Sheet) =\u003e Sheet;\n\tgetCharset: () =\u003e string;\n\tgetNSheets: () =\u003e number;\n\tgetSheet: (i: number) =\u003e Sheet;\n\tgetSheets: () =\u003e Sheet[];\n\tgetType: () =\u003e string;\n\tsetCharset: (charset: string) =\u003e BaseWriter;\n\tsetType: (type: string) =\u003e BaseWriter;\n\tsaveFile: (name: string = 'download', noAutoBom: boolean = false) =\u003e void;\n}\n\nclass SVWriter extends BaseWriter {\n\tconstructor: (delimiter: string = ',', type: string = 'text/csv', charset: string = 'utf-8') =\u003e SVWriter;\n\tgetData: () =\u003e string;\n\tgetDelimiter: () =\u003e string;\n\tgetBlob: () =\u003e Blob;\n\tsetDelimiter: (delimiter: string) =\u003e SVWriter;\n}\n\nclass CSVWriter extends SVWriter {}\n\nclass TSVWriter extends SVWriter {}\n```\n\n## Examples\n\n```js\n// CSV contents from html input source\nconst inputElementFileOnChangeFunction = async function(event){\n\tconst file = this.files \u0026\u0026 this.files[0];\n\n\tif(file){\n\t\tconst csvParser = new Spreadsheets.parsers.CSV();\n\n\t\tawait csvParser.loadFile(file);\n\n\t\tconst csvSheet = await csvParser.parseFile();\n\n\t\tcsvSheet.forEach((row, r) =\u003e {\n\t\t\trow.forEach((cell, c) =\u003e {\n\t\t\t\tconsole.log(`Cell (${r}, ${c}) Value: ${cell.get()}`);\n\t\t\t});\n\t\t});\n\t}\n};\n\n\n// CSV contents from non-html input source\nconst csvRaw = [\n\t[\n\t\t'Row 1 Col 1',\n\t\t'Row 1 Col 2',\n\t\t'Row 1 Col 3'\n\t].join(','),\n\t[\n\t\t'Row 2 Col 1',\n\t\t'Row 2 Col 2',\n\t\t'Row 2 Col 3'\n\t].join(','),\n\t[\n\t\t'Row 3 Col 1',\n\t\t'Row 3 Col 2',\n\t\t'Row 3 Col 3'\n\t].join(',')\n].join('\\n');\n\nconst csvParser = new Spreadsheets.parsers.CSV();\n\nconst csvBlob = new Blob([ csvRaw ], {\n\ttype: 'text/csv'\n});\n\nawait csvParser.setContents(csvBlob);\n\nconst csvSheet = await csvParser.parseFile();\n\ncsvSheet.forEach((row, r) =\u003e {\n\trow.forEach((cell, c) =\u003e {\n\t\tconsole.log(`Cell Value A: ${cell.get()}`);\n\n\t\tcell.set(`Col ${c} Row ${r}`);\n\n\t\tconsole.log(`Cell Value B: ${cell.get()}`);\n\t});\n});\n\nconst csvWriter = new Spreadsheets.writers.CSV();\n\ncsvWriter.addSheet(csvSheet);\n\nawait csvWriter.saveFile('new.csv');\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftflanagan%2Fjs-spreadsheets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftflanagan%2Fjs-spreadsheets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftflanagan%2Fjs-spreadsheets/lists"}