|
@@ -4,29 +4,30 @@ let getBuffer = function(){
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
const x = new XMLHttpRequest();
|
|
|
x.open("GET", 'file/附件 5 :学校创客专项资金使用申请表.xlsx', true);
|
|
|
- x.responseType = "blob";
|
|
|
+ x.responseType = "blob"; //
|
|
|
x.send()
|
|
|
x.onreadystatechange = function(){
|
|
|
if(x.readyState==4 && x.status==200){
|
|
|
let reader = new FileReader();
|
|
|
- reader.readAsArrayBuffer(x.response)
|
|
|
- reader.onload = function(){
|
|
|
- resolve(reader.result)
|
|
|
+ console.log(x.response);
|
|
|
+ reader.readAsArrayBuffer(x.response) //读取返回回来的文件内容
|
|
|
+ reader.onload = function(){ //当读取操作成功完成时调用
|
|
|
+ console.log(reader);
|
|
|
+ resolve(reader.result) //reader.result返回文件内容
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-export default async function getExcel(data){
|
|
|
- console.log(data);
|
|
|
- const content = await getBuffer();
|
|
|
+export default async function getExcel(data){ //async 申明 function 是异步的,而 await 等待某个操作完成。
|
|
|
+ // console.log(data);
|
|
|
+ const content = await getBuffer(); //等待getBuffer函数执行完成
|
|
|
const workbook = new Excel.Workbook();
|
|
|
- await workbook.xlsx.load(content);
|
|
|
+ await workbook.xlsx.load(content); //从 buffer 加载
|
|
|
//获取第一个worksheet
|
|
|
let worksheet = workbook.getWorksheet(1);
|
|
|
|
|
@@ -34,7 +35,7 @@ export default async function getExcel(data){
|
|
|
//项目类型
|
|
|
// worksheet.getCell("G2").value='项目类型:创客空间 □ 创客实践室 □ 个人创客 □ 创客活动 □ '
|
|
|
//项目名称
|
|
|
- worksheet.getCell('G3').value=`项目名称: ${data.PName}`;
|
|
|
+ worksheet.getCell('G3').value=`项目名称:${data.PName}`;
|
|
|
//备注
|
|
|
worksheet.getCell("G18").value=data.remarks;
|
|
|
|
|
@@ -256,7 +257,7 @@ export default async function getExcel(data){
|
|
|
|
|
|
//下载excel文件
|
|
|
let blob = new Blob([await workbook.xlsx.writeBuffer()], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"});
|
|
|
- let url = window.URL.createObjectURL(blob);
|
|
|
+ let url = window.URL.createObjectURL(blob); // 字符内容转变成blob地址
|
|
|
const link = document.createElement('a');
|
|
|
link.style.display = 'none';
|
|
|
link.href = url;
|