From json to sheet. #610
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#610
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi guys,
thanks for the wonderful work on this module.
Some quick questions:
sheet_to_json
utility...json_to_sheet
utility. To be able to write back the changed xls to the file.Thanks
If you pass
header:1
andraw:true
tosheet_to_json
, you get an array of arrays of the original values. You can iterate across those fairly easily. It's explained in the docs: https://sheetjs.gitbooks.io/docs/#jsonTo convert the array of arrays back to a worksheet, you can use the
aoa_to_sheet
utility. It's explained in the docs: https://sheetjs.gitbooks.io/docs/#array-of-arrays-input.Please skim those sections and let us know how we can improve them.
Thanks for your reply!
As first thing I'd say, highlight the documentation, I didn't even see that documentation! Is it even linked to the README?
It's actually all in the readme, the gitbook links are basically re-rendering the README.
https://github.com/SheetJS/js-xlsx#json
https://github.com/SheetJS/js-xlsx#array-of-arrays-input
These are pretty undiscoverable because the README is huge. I like the gitbook style with the links on the left sidebar
@roccomuso this was as good a time as any to play with the RunKit service. Here's a little notebook that demonstrates how to change data using the JSON form: https://runkit.com/sheetjs/58dc6ea1eae8b800146359eb
Btw a
json_to_sheet
utility wouldn't be bad for those who are more familiar with JSON.@roccomuso Here's a simple function, we should add a more refined version of this to the library in the next release:
@SheetJSDev Thank you!! This is EXACTLY what I needed. I am looking forward to finding it in a future release!
In my case, I wanted to convert a result of a mongoDB query ( an array of objects) to excel, and this function does exactly that :)
@SheetJSDev Can you share sample code to generate json to xlsx with this sample data?
[ { "agentNo":"324234", "subName":"30, Jul 2013 09:24 AM" }, { "agentNo":"444443", "subName":"30, Jul 2013 09:24 AM" } ]
I'm stucked with this part
@samuelkavin
I use something like this to create a xlsx file from json and send it as a response to a web request:
how to use json_to_sheet for angular2? when i install the package npm js-xlsx, in the dist folder json_to_sheet function is not present in any file xlsx.full.min.js, xlsx.core.min.js
@koolhuman the official npm name is
xlsx
@reviewher do i need to import any typings for xlsx? I installed xlsx package version 0.11.9, but it does not compile and shows error-
error TS2339: Property 'json_to_sheet' does not exist on type 'IUtils'.
I imported the package in my component.
import * as XLSX from 'xlsx';
public exportAsExcelFile(json: any[], excelFileName: string): void {
const worksheet: any = XLSX.utils.json_to_sheet(json);
const workbook: any = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'binary' });
this.saveAsExcelFile(excelBuffer, excelFileName);
}
Cannot resolve symbol utils.
The typings are included with the library now. Remove
@types/xlsx
andts-xlsx
if you have those installed@reviewher - I removed
@types/xlsx
and I did not hadts-xlsx
installed. After removing now the compile error shows-error TS7016: Could not find a declaration file for module 'xlsx'.
How do i import xlsx module in my angular 2 component?
Currently my import looks like -
import * as XLSX from 'xlsx'
;And then i use the XLSX in function as below.
After changing
import * as XLSX from 'xlsx';
toconst XLSX = require('xlsx');
Everything worked fine. Thanks again @reviewher for helping me out.@koolhuman The angular 2+ demo in
demos/angular2
uses theimport * as XLSX from 'xlsx'
form.I just checked and it still seems to work. To verify on angular 2:
Can you check if that works for you?
I am using Angular 4.0 and webpack. should that be an issue?
Repeat the same steps above except use the angular4 configuration:
The demo uses the angular CLI to generate a new project. Ejecting generates a web pack config!
Here is the generated
webpack.config.js
. Compare this webpack config as well as thetsconfig.json
to see if you have any different options@reviewher - I can see in below link, there is some configuration done for webpack, do you think i might be missing something like that.
https://github.com/SheetJS/js-xlsx/tree/master/demos/webpack#reflecting-the-xlsx-variable
@reviewher - Thanks again, after changing my tsconfig.js file to the one you referred in your post the application compiles fine. Now i am able to use
import * as XLSX from 'xlsx';
My earlier tsconfig.js looked like below
Changed to
Is it possible to convert json from the excel which should be parse with column wise?