javascript - How to Convert nested(Complex) JSON to excel IN Jquery?
问题描述
Is there any way to convert complex json to Excel format? For Example:
{
"accounting" : [
{ "firstName" : "John",
"lastName" : "Doe",
"age" : 23 }
],
"sales" : [
{ "firstName" : "Sally",
"lastName" : "Green",
"age" : 27 }
]
}
解决方案
我们公司正在使用 Kendo UI 在 JavaScript 中创建 Excel 文档。但这不是免费产品。https://docs.telerik.com/kendo-ui/framework/excel/introduction
如果链接断开。
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.js"></script>
<script src="http://kendo.cdn.telerik.com/2018.3.1017/js/kendo.all.min.js"></script>
<script>
var workbook = new kendo.ooxml.Workbook({
sheets: [
{
// Column settings (width)
columns: [
{ autoWidth: true },
{ autoWidth: true }
],
// Title of the sheet
title: "Customers",
// Rows of the sheet
rows: [
// First row (header)
{
cells: [
// First cell
{ value: "Company Name" },
// Second cell
{ value: "Contact" }
]
},
// Second row (data)
{
cells: [
{ value: "Around the Horn" },
{ value: "Thomas Hardy" }
]
},
// Third row (data)
{
cells: [
{ value: "B's Beverages" },
{ value: "Victoria Ashworth" }
]
}
]
}
]
});
kendo.saveAs({
dataURI: workbook.toDataURL(),
fileName: "Test.xlsx"
});
</script>
推荐阅读
- docker - python + mysql - 通过 docker-compose 创建
- java - 找不到局部变量,这是一个公共类
- python - 从列表中的元素中获取最常用的单词
- solr - 如何修复无法创建核心 [博客] 原因:solr.SortableIntField
- java - Spring Boot @StepScope 错误'不能子类化最终类 java.lang.String'
- python - 在 Python 中使用 Plotly 进行 QQ 绘图
- c# - 在现有代码c#中实现循环
- reactjs - 使用 /home 中的 .eslintrc 并在 VScode 中全局安装 eslint
- python - Numpy如何从一个三维数组中找到第三维的索引(例如x,y)
- php - 文件(文件描述符 3)存在但无法通过 fopen php 打开