123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <html>
- <head>
- <title>echarts 力导向图</title>
- <meta charset="UTF-8">
- <!-- <script type="text/javascript" src="js/jquery-1.9.0.min.js" ></script> -->
- <script src="/static/js/jquery.min.js"></script>
- <script type="text/javascript" src="https://cdn.staticfile.org/xlsx/0.15.1/xlsx.core.min.js"></script>
- <script src="/static/js/vue-2.4.0.js"></script>
- </head>
- <body>
- <div id="app">
- <input type="file" @change="tirggerFile($event)">
- <button @click="aa()">上传</button>
- </div>
- </body>
- <script>
- var vm = new Vue({
- el: '#app',
- data: {
- data_timeqi: '', //查询时间起
- data_timezhi: '', //查询时间止
- },
- mounted() {
- },
- methods: {
- aa() {
- console.log(11111)
- window.onload = function () {
- $('#excel-file').change(function (e) {
- var files = e.target.files;
- var fileReader = new FileReader();
- fileReader.onload = function (ev) {
- try {
- var data = ev.target.result
- var workbook = XLSX.read(data, {
- type: 'binary'
- }); // 以二进制流方式读取得到整份excel表格对象
- persons = [];
- } catch (e) {
- alertMsg(2, '文件类型不正确, 请重新选择文件');
- return;
- }
- // 表格的表格范围,可用于判断表头是否数量是否正确
- var fromTo = '';
- // 遍历每张表读取
- for (var sheet in workbook.Sheets) {
- if (workbook.Sheets.hasOwnProperty(sheet)) {
- fromTo = workbook.Sheets[sheet]['!ref'];
- if (!fromTo) {
- alert(2, '文件内容为空, 导入失败');
- return;
- }
- persons = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
- // break; // 如果只取第一张表,就取消注释这行
- }
- }
- console.log(persons);
- //将persons赋值给要展示的表格数组里即可展示在界面
- };
- // 以二进制方式打开文件
- if (files.length == 0) {
- return;
- }
- fileReader.readAsBinaryString(files[0]);
- e.target.value = '';
- });
- }
- },
- tirggerFile(e) {
- var files = e.target.files;
- var fileReader = new FileReader();
- fileReader.onload = function (ev) {
- try {
- var data = ev.target.result
- var workbook = XLSX.read(data, {
- type: 'binary'
- }); // 以二进制流方式读取得到整份excel表格对象
- persons = [];
- } catch (e) {
- alertMsg(2, '文件类型不正确, 请重新选择文件');
- return;
- }
- // 表格的表格范围,可用于判断表头是否数量是否正确
- var fromTo = '';
- // 遍历每张表读取
- for (var sheet in workbook.Sheets) {
- if (workbook.Sheets.hasOwnProperty(sheet)) {
- fromTo = workbook.Sheets[sheet]['!ref'];
- if (!fromTo) {
- alert(2, '文件内容为空, 导入失败');
- return;
- }
- persons = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
- // break; // 如果只取第一张表,就取消注释这行
- }
- }
- console.log(persons);
- //将persons赋值给要展示的表格数组里即可展示在界面
- };
- // 以二进制方式打开文件
- if (files.length == 0) {
- return;
- }
- fileReader.readAsBinaryString(files[0]);
- e.target.value = '';
- }
- },
- created() {
- }
- });
- </script>
- </html>
|