uniapp APP流文件execl 下载并用WPS打开

文章介绍了如何在小程序中利用`plus.downloader.createDownload`方法下载WPS文件,然后通过`uni.openDocument`打开文件,展示了从请求头配置到封装函数的详细过程。
摘要由CSDN通过智能技术生成

流程是先将文件下载,到本地,然后使用openDocument打开本地路径

需要下载WPS文件,以下是模拟器打开效果

使用plus.downloader.createDownload 方法将新建下载任务

HTML5+ API Reference

export default function plusDownload(config){
    if(!config)
	{
		console.error("Argument should not be null");
		return;
	}
    const url=request.baseUrl+config.url;

    let token = uni.getStorageSync("token");
        let	header={
	    //	'Content-Type':"application/octet-stream",
		'Authorization':"Bearer " + token
		//'Accept':'*/*'
	};
    config.header=config.header||{};
    Object.assign(header,config.header);
    
   
  let download= plus.downloader.createDownload(url,config,(d,s)=>config.complete(d,s,download));

  download.setRequestHeader('Authorization',"Bearer " + token);
  
  download.start();
}

封装方法

export function downloadInspectionResult(data) {
 
   uni.showLoading({title:'读取文件...',duration:10000});
    plusDownload({
         url:'/ny-iqc/incomingInspection/exportCoa?id='+data.id,
     
        method: 'POST',
        filename: '_downloads/'+data.fileName,
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: data,
        complete: function (res,status,download) {

            uni.hideLoading();
            
           uni.openDocument({
            filePath: res.filename,
            fileType: 'xlsx',
            showMenu: true,
            success: () => {
              uni.showToast({
                title: '打开文档成功',
                icon: 'success',
                mask: true,
              });
            },
            fail: (error) => {
              console.log('error', error);
                },
          });

        },
      
    });
}

调用封装的方法

downloadInspectionResult({
        id:id,
        fileName: fileName
 });

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三线码工

码字不易,有钱打赏,没打钱点赞

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值