Applet download pdf, excel, word function (solved)

  downloadFile(){
    wx.showLoading({
      title: '正在下载并打开',
    })
    wx.downloadFile({
      url: 'https://xxx.xxx.com/路径.xls',
      header: {
        'content-type': 'multipart/form-data',
        'Authorization': 'Bearer ' + wx.getStorageSync('token'),
      },
      success: function(res) {
        wx.hideLoading()
        // wx.saveFile({
          wx.getFileSystemManager().saveFile({
          tempFilePath: res.tempFilePath,
          filePath: wx.env.USER_DATA_PATH + "/文件名"  + '.xlsx',
          success: function(res) {
            wx.openDocument({
              filePath: res.savedFilePath,
              showMenu:true,
              success: function(res) {
              },
              fail(err) {
                app.Tips({
                  title: '简历打开失败',
                  icon:"error"
                });
                console.log(err);
              }
            })
          },
          fail(err) {
            app.Tips({
              title: '简历临时保存失败',
              icon:"error"
            });
            console.log(err);
          }
        })
      },
      fail(err) {
        wx.hideLoading()
        app.Tips({
          title: '简历下载失败',
          icon:"error"
        });
        console.log(err);
      }
    })
  },

 

 Ask me in the comment area if you don’t understand anything~

Guess you like

Origin blog.csdn.net/ZHANG157111/article/details/130748335