Make data vertically instead of horizontally. #2866

Closed
opened 2023-01-27 07:25:54 +00:00 by kieunam123 · 1 comment

I need to convert an array of json object to workbook using the following data:

data = [{ 
    		"header1" : "detail1",
           	"header2" : "detail2",
        	"header3" : [{
                	"subheader1" : "subdetail1"
               		"subheader2" : "subdetail2"
            	 }]
         
       	}]

Expected result :
image

Is this possible? Thanks in advance.

I need to convert an array of json object to workbook using the following data: ``` data = [{ "header1" : "detail1", "header2" : "detail2", "header3" : [{ "subheader1" : "subdetail1" "subheader2" : "subdetail2" }] }] ``` Expected result : ![image](/attachments/d8129460-ac00-4a7d-8a2e-3b9074f81058) Is this possible? Thanks in advance.
6.5 KiB
Owner

Translate the data to the shape you need, then use aoa_to_sheet or json_to_sheet to pull data.

For example, using the literal names:

const massaged_data = data.map(({ header1, header2, header3: { subheader1, subheader2 }}) => ({
  header1,
  header2,
  subheader1,
  subheader2
}));
const ws = XLSX.utils.json_to_sheet(massaged_data);

https://docs.sheetjs.com/docs/getting-started/example includes a more involved example.

Translate the data to the shape you need, then use `aoa_to_sheet` or `json_to_sheet` to pull data. For example, using the literal names: ```js const massaged_data = data.map(({ header1, header2, header3: { subheader1, subheader2 }}) => ({ header1, header2, subheader1, subheader2 })); const ws = XLSX.utils.json_to_sheet(massaged_data); ``` https://docs.sheetjs.com/docs/getting-started/example includes a more involved example.
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#2866
No description provided.