XLSX Angular Extort从一张纸中的嵌套阵列出口表
我正在使用此软件包 xlsx
想要导出excel Sheet示例中添加的对象导出的嵌套阵列下面添加的excel Sheet示例,请帮忙!
let data = [
{
"product": "Test Product",
"id": 1,
"childProduct": [
{ name: "Child Product 1", "id": 11 },
{ name: "Child Product 2", "id": 12 }
]
},
{
"product": "Test Product",
"id": 1,
"childProduct": [
{ "name": "Child Product 1", "id": 13 },
{ "name": "Child Product 2", "id": 14 }
]
}
]
我已经尝试过这种解决方案,但是它不起作用,它总是替换最后一个数据。
let wb = xlsx.utils.book_new();
data.map((item: any) => {
xlsx.utils.json_to_sheet(item.childProduct);
})
单板应该像这样:
I am using this package xlsx
Wanted to export nested array of object export in excel sheet example added below, please help!
let data = [
{
"product": "Test Product",
"id": 1,
"childProduct": [
{ name: "Child Product 1", "id": 11 },
{ name: "Child Product 2", "id": 12 }
]
},
{
"product": "Test Product",
"id": 1,
"childProduct": [
{ "name": "Child Product 1", "id": 13 },
{ "name": "Child Product 2", "id": 14 }
]
}
]
I have tried this solutions, but it isn't work it always replace last data.
let wb = xlsx.utils.book_new();
data.map((item: any) => {
xlsx.utils.json_to_sheet(item.childProduct);
})
Single sheet should be like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是用于简单格式的。
This is for simple format.
我不确定是否有一种更优雅的方法可以使用内置的XLSX库方法来执行此操作,但是您可以转换数据以获取所需的输出。
阵列您将传递到
json_to_sheet
函数必须像这样构建:将数据转换为新数组的导出:
使用库的导出数据:
I am not sure if there is a more elegant way to do this with built-in xlsx library methods, but you can transform data to get desired output.
Array you pass into
json_to_sheet
function has to be structured like this:Transform data into new array for export:
Export data using library: