json2xlsx AND xlsx2json 接口
来源:互联网 发布:access与sql的区别 编辑:程序博客网 时间:2024/04/28 00:09
因为业务需要所以用nodejs做了两个转换excel和json的接口
以下是这两个接口的文档
excel文件转json接口:
导入excel文件(兼容office2003以后版本)
因为业务原因当时只做了两列的读取
格式是
姓名 手机号码
阿西西 125456564565
......
最后返回一个json格式数组
json导出excel接口:
一行一行读取
ajax内传输的数据格式
data:{head:hh,data:dd}
hh是第一行title的内容,以数组形式定义。
hh是主要数据的内容,以对象形式定义。
代码如下。
var _headers = ['id', 'name', 'age', 'country', 'remark', 'remark']var _data = [ { id: '1',name: 'test1',age: '30',country: 'China',remark: 'hello',remark: 'hello' },{ id: '2',name: 'test2',age: '20',country: 'America',remark: 'world',remark: 'hello' },{ id: '3',name: 'test3',age: '18',country: 'Unkonw',remark: '???' ,remark: 'hello' }];var dd = JSON.stringify(_data);var hh = JSON.stringify(_headers);<span style="white-space:pre"></span>
document.getElementById("exmple").onclick = function() {$.ajax({url: 'http://121.42.42.155:8888/excel',type:"POST",data: {head:hh,data:dd},dataType: "json",success: function(data) {},error: function(xhr, status, error) {console.log('Error: ' + error.message);},});}因为js无法直接下载文件(不然就各种js直接下载文件,分分钟中毒呀),所以做成弹出框“文件已准备就绪,是否下载?是/否。”
‘是’按钮连接到文件位置
<a href="http://121.42.42.155:8888/output.xlsx">是</a>
1 0
- Linux下安装DB2数据库步骤
- PAT1023组个最小数 (20)
- 【追求进步】数字在排序数组中出现的次数
- GPU 加速下的图像处理
- Android聊天页面发送图片定制(类似微信)
- json2xlsx AND xlsx2json 接口
- Apache服务器无法获取Authorization Header
- Strtus2——request、response等内置对象的获取方式
- fork 子进程不继承父进程打开的文件描述符
- Linux export --设置或显示环境变量
- Java命令行简单知识点
- Activity生命周期图
- UICollectionView-设置弹簧效果是否显示滚动条等向
- maven创建java项目和javaWeb项目