|
@@ -0,0 +1,48 @@
|
|
|
+import Excel from 'exceljs'
|
|
|
+
|
|
|
+let getBuffer = function(){
|
|
|
+ return new Promise((resolve,reject)=>{
|
|
|
+ const x = new XMLHttpRequest();
|
|
|
+ x.open("GET", 'file/附件 5 :学校创客专项资金使用申请表.xlsx', true);
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+export default async function getExcel(data){
|
|
|
+ const content = await getBuffer();
|
|
|
+ const workbook = new Excel.Workbook();
|
|
|
+ await workbook.xlsx.load(content);
|
|
|
+ //获取第一个worksheet
|
|
|
+ let worksheet = workbook.getWorksheet(1);
|
|
|
+
|
|
|
+ // 在这里设置表格的内容
|
|
|
+ worksheet.getCell('C7').value = 100;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let blob = new Blob([await workbook.xlsx.writeBuffer()], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"});
|
|
|
+ let url = window.URL.createObjectURL(blob);
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.style.display = 'none';
|
|
|
+ link.href = url;
|
|
|
+ link.setAttribute('download', '学校创客专项资金使用申请表.xlsx');
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+}
|
|
|
+
|