当前位置:网站首页>Getting started with web programming 2.2 reading parameters in Excel and XML
Getting started with web programming 2.2 reading parameters in Excel and XML
2022-07-22 21:44:00 【A chicken with multiple senses】
(1) Read Excel Parameters in
Need to import external files , from github find xlsx.core.min.js, Download and import
And then in HTML Set upload control in
<input type="file" id="excel-file">
Then listen for control change events
$('#excel-file').change(function(e) {
var files = e.target.files;
var fileReader = new FileReader();
fileReader.onload = function(ev) {
try {
var data = ev.target.result,
workbook = XLSX.read(data, {
type: 'binary'
}), // Read in binary stream to get the whole copy excel Table objects
persons = []; // Store the acquired data
} catch (e) {
console.log(' load EXCEL File error !');
return;
}
// Table range of the table , It can be used to judge whether the header quantity is correct
var fromTo = '';
// Traverse each table and read
for (var sheet in workbook.Sheets) {
if (workbook.Sheets.hasOwnProperty(sheet)) {
fromTo = workbook.Sheets[sheet]['!ref'];
console.log(fromTo);
persons = persons.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
// break; // If you only take the first table , Just uncomment the line
}
}
};
// Open the file in binary mode
fileReader.readAsBinaryString(files[0]);
});
resulting persons Is the corresponding parameter set .
(2) Read XML Parameters in
Use ajax Method to access xml file , But in the visit xml Need to get the document before the document url Address , So first read the address , Then you can access the corresponding address XML file .
$('#fileField').change(function(e) {
var url = null;
var fileObj = document.getElementById("fileField").files[0];
if (window.createObjcectURL != undefined) {
url = window.createOjcectURL(fileObj);
} else if (window.URL != undefined) {
url = window.URL.createObjectURL(fileObj);
} else if (window.webkitURL != undefined) {
url = window.webkitURL.createObjectURL(fileObj);
}
$.ajax({
url: url,
dataType: 'xml',
type: 'GET',
async:false,
error: function(xml)
{
alert(" load XML File error !");
},
success: function(xml)
{
$(xml).find("e").each(function(i)
{
var orderid = $(this).children(" Order ID").text();
var clothid = $(this).children(" Order product ID").text();
var clothamount = $(this).children(" Order quantity ").text();
//var buckle = $(this).children("buckle").text();
console.log(orderid+" "+clothid+" "+clothamount);
});
fillformbyxml(xml);
}
});
});
边栏推荐
- 6. Echo and redirection
- 蓝桥杯-递增三元组
- Function of extern "C"
- Web编程入门 3.1 选择框select
- Copy, cut and paste of C WinForm development files / folders
- 7-1 detailed steps of installing SSH on virtual machine
- Data interaction between C # WinForm development forms
- 6.拷贝移动及文件内容命令
- Hnoi2003 laser bomb
- Copying files between two servers SCP method
猜你喜欢
C# Winform开发 打开txt文件 并显示在 RichTextBox中 加上编辑后保存功能
Blue Bridge Cup - incremental triples
水库防汛泄洪抢险应急广播系统建设4G无线广播模式分析
C# Winform开发 文件/文件夹的复制 剪切 粘贴
重新安装的nvidia显卡驱动
10.系统信息相关命令
7-1虚拟机上安装SSH的详细步骤
Web编程入门 3.1 选择框select
Blue Bridge Cup - underground palace treasure taking
Safety first, where is the strength of Beijing modern i-gmp platform?
随机推荐
C WinForm development opens the txt file and displays it in RichTextBox. Add the function of saving after editing
How to login to a remote host without secret via SSH
Introduction to web programming use of adminlte framework
喝汽水情景 2: 递归
Web编程入门 1.2页面跳转
Automated test JSON general parser
【问题篇】IDEA运行war包项目
Wechat applet introduction tutorial learning notes - layout basis of UI chapter
shell远程执行命令
6. Copy, move and file content commands
解决编译mosquitto时遇到的问题
Web编程入门 2.3 解决fakepath问题 获取本地文件真实地址
this的指向和用法
C WinForm development file / folder creation
Record: problem 1, computer flash screen; Problem 2: double clicking the computer desktop icon does not respond
Web编程入门 1.4 PHP连接数据库 PDO
Cartesi 2022 年 3 月回顾
闭包的常见用法
Cjson source code reading notes
Winappdriver automatic test deployment of WinForm automatic test