uniapp中写的安卓app,内嵌一个webview组件,里面是自己写得外部h5网页,在这个h5外部网页中的其中一个页面,我使用了exceljs导出一个exceljs表,在浏览器中就可以下载,但是一道手机app跳转到外部网页后点击导出按钮,就弹出一个弹框‘是否确认下载’,点击确认后没有反应
exportExcel22(data) {
const workbook = new ExcelJS.Workbook()
const worksheet = workbook.addWorksheet('Sheet 1')
// 设置标题样式
const titleStyle = {
font: {
bold: true
},
alignment: {
vertical: 'middle',
horizontal: 'center'
},
border: {
bottom: {
style: 'none'
},
},
};
// 添加标题并设置样式
worksheet.mergeCells('A2:E2');
worksheet.getCell('A2').value = '库存数量表';
worksheet.getCell('A2').style = titleStyle;
// 添加数据并设置样式
data.forEach((item, index) => {
const row = 6 + index; // 从第五行开始添加数据
worksheet.getCell(`A${row}`).value = item.whdt_zbgno;
worksheet.getCell(`B${row}`).value = item.whdt_stno;
worksheet.getCell(`C${row}`).value = item.whdt_zbno;
worksheet.getCell(`D${row}`).value = item.whdt_zbna;
worksheet.getCell(`E${row}`).value = item.whdt_num;
// 添加表头
worksheet.getCell('A5').value = '库房编号';
worksheet.getCell('B5').value = '储位编号';
worksheet.getCell('C5').value = '装备编号';
worksheet.getCell('D5').value = '装备名称';
worksheet.getCell('E5').value = '装备数量';
// 设置边框样式
const borderStyle = {
top: {
style: 'thin'
},
right: {
style: 'thin'
},
bottom: {
style: 'thin'
},
left: {
style: 'thin'
},
};
//表头样式
worksheet.getCell('A5').border = borderStyle;
worksheet.getCell('B5').border = borderStyle;
worksheet.getCell('C5').border = borderStyle;
worksheet.getCell('D5').border = borderStyle;
worksheet.getCell('E5').border = borderStyle;
//内容
worksheet.getCell(`A${row}`).border = borderStyle;
worksheet.getCell(`B${row}`).border = borderStyle;
worksheet.getCell(`C${row}`).border = borderStyle;
worksheet.getCell(`D${row}`).border = borderStyle;
worksheet.getCell(`E${row}`).border = borderStyle;
});
// 设置所有单元格居中
worksheet.eachRow(row => {
row.eachCell(cell => {
cell.alignment = {
vertical: 'middle',
horizontal: 'center'
};
});
});
// 导出Excel文件
workbook.xlsx.writeBuffer().then((buffer) => {
const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
});
const url = window.URL.createObjectURL(blob);
console.log(url,'999');
// 创建一个<a>标签并设置下载链接
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', '库存数量表.xlsx');
// 触发点击事件进行下载
link.click();
// 释放URL对象
window.URL.revokeObjectURL(url);
});
},
//生成excel表
exportExcel() {
if (this.searchResults.length == 0) {
if (this.list1.length == 0) {
uni.showToast({
title: '请进行筛选',
icon: 'error'
})
} else {
this.exportExcel22(this.list1)
// console.log('if');
}
} else {
this.exportExcel22(this.searchResults)
// console.log('else');
}
},