国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序中pdf的上傳、下載及excel導出

這篇具有很好參考價值的文章主要介紹了微信小程序中pdf的上傳、下載及excel導出。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

pdf上傳

上傳兩種方法:

上傳1:

1.用vant weapp組件:

//pdf上傳--vant weapp組件
<view class="content">
    <van-uploader
     file-list="{{ fileList }}"  
     bind:after-read="afterReadFile" 
     accept="file"  
     upload-icon="plus"
     preview-size="30px"
     max-count="1"
     deletable="{{deletableFile}}"
    >
    </van-uploader>
</view> 

page({
  data:{
  	fileList:[],//pdf上傳
  }
})
                
afterReadFile: function (e) {
    let that = this;
    const { file } = e.detail;
    let myId = that.data.myId; //
  
    console.log(file,1000);
    wx.uploadFile({
        url: api.hhh+'?file='+file.url+'&schedulingId='+myId,//服務器上的pdf地址
        filePath: file.url,
        name: 'file',
        // formData: { 
        //     file: file.url,
        //     schedulingId:myId
        // },
        success(res) {
          // 上傳完成需要更新 fileList
          const { fileList = [] } = that.data;
          fileList.push({ ...file });
          that.setData({ fileList });
        },
      });
},

上傳2:

<view class="content" bindtap="uploadFileTap">
    上傳
</view>

//pdf上傳--原生組件
uploadFileTap:function(e){
	let that = this;
	let myId = that.data.myId; 
	wx.chooseMessageFile({
	    count: 1,
	    type: 'file',
	    success (res) {
	      // tempFilePath可以作為img標簽的src屬性顯示圖片
	      const tempFilePaths = res.tempFiles
	      wx.uploadFile({
	        url: url,//服務器上的pdf地址 
	        filePath: tempFilePaths[0].path,
	        name: 'file',
	        formData: {
	            file: tempFilePaths[0].path,
	            schedulingId:myId
	        },
	        success (res){
	          const data = res.data
	          //do something
	          wx.showToast({
	            title: '數(shù)據(jù)上傳成功!',
	            icon: 'none',
	            duration: 3000
	            })
	        }
	      })
	    }
	  })
},

pdf下載

參考:https://blog.csdn.net/weixin_38566069/article/details/110229404

//下載pdf
downloadPDF:function(e){
   let that = this;
   let myId = that.data.myId; 

   wx.showLoading({
       title: '加載中...',
       mask: true
   });
   //獲取pdf地址
   app.get(api.xxxx, {
       schedulingId: myId, //
   }).then(res => {
       if (res.code == 200) {
           wx.hideLoading()
           let pdfUrl=res.data ? (res.data.pdfUrl ? res.data.pdfUrl : null) : null
           if(pdfUrl){
               const fileExtName = ".pdf";
               const randfile = new Date().getTime() + fileExtName;
               const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`;
               that.deletContract();
               //下載
               wx.downloadFile({
                   url: pdfUrl,
                   filePath: newPath,
                   success: function (res) {
                   const filePath = res.tempFilePath;
                       wx.openDocument({
                       filePath: newPath,
                       showMenu: true,
                       fileType: 'pdf',
                       success: function (res) {}
                   })
                   },
                   fail: function (res) {
                   wx.hideLoading();
                   }
               })
           }else{
               wx.showToast({
                   title: '請先上傳pdf數(shù)據(jù)!',
                   icon: 'none',
                   duration: 3000
               })
           }

       } else {
           wx.hideLoading()
           wx.showToast({
               title: '獲取數(shù)據(jù)失敗!',
               icon: 'none',
               duration: 3000
           })
       }
   }).catch((err) => {
       wx.hideLoading()
       wx.showToast({
           title: 'err',
           icon: 'none',
           duration: 3000
       })
   });
},

// 刪除本地文件
deletContract() {
   try {
   let file = wx.getFileSystemManager();
   file.readdir({
       dirPath: `${wx.env.USER_DATA_PATH}`,
       success: res => {
           console.log(res);
           if (res.files.length > 2) {
               file.unlink({
               filePath: `${wx.env.USER_DATA_PATH}/${res.files[0]}`,
               complete: res => {}
               })
           }
       }
   })
   } catch (error) {}
},

導出excel

//導出Excel
  downloadExcel:function(e){
      let that = this;
      let myId = that.data.myId; 

      wx.showLoading({
          title: '加載中...',
          mask: true
      });
      app.get(api.xxxExcel, {
          schedulingId: myId, 
      }).then(res => {
          if (res.code == 200) {
              let excelUrl=res.data ? res.data : null
              if(excelUrl){
                  let type=excelUrl.split('.').pop();
                  let fileExtName = "";
                  if(type==''){//空
                      wx.showToast({
                          title: '導入的非Excel文件!',
                          icon: 'none',
                          duration: 3000
                      })
                      return false
                  }else if(type=='xls'){
                      fileExtName=".xls"
                  }else if(type=='xlsx'){
                      fileExtName=".xlsx"
                  }

                  const randfile = new Date().getTime() + fileExtName;
                  const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`;
                  that.deletContract();
                  wx.downloadFile({
                      url: excelUrl,
                      filePath: newPath,
                      success: function (res) {
                          wx.hideLoading()
                          const filePath = res.filePath;
                          wx.openDocument({
                              filePath: newPath,
                              showMenu: true,
                              fileType: type,
                              success: function (res) {}
                          })
                      },
                      fail: function (res) {
                          wx.hideLoading();
                      }
                  })
              }else{
                  wx.showToast({
                      title: '請先上導入Excel數(shù)據(jù)!',
                      icon: 'none',
                      duration: 3000
                  })
              }
        

          } else {
              wx.hideLoading()
              wx.showToast({
                  title: '獲取Excel數(shù)據(jù)失??!',
                  icon: 'none',
                  duration: 3000
              })
          }
      }).catch((err) => {
          wx.hideLoading()
          wx.showToast({
              title: 'err',
              icon: 'none',
              duration: 3000
          })
      });
  },

提示:突然冒出一個報錯:wx.chooseMessageFile點擊很多次后就突然無效了
昨天上傳功能在【微信開發(fā)工具和移動端】都可以用,早上突然實現(xiàn)了。
查了下是官方給出的解釋是:
2023年9月15日之前,此功能邏輯只對開發(fā)版/體驗版生效,開發(fā)者請盡快進行隱私彈窗適配、發(fā)版。2023年9月15日之后,將對正式版生效,詳情可見《關(guān)于小程序隱私保護指引設(shè)置的公告》。

具體見:
https://developers.weixin.qq.com/community/develop/doc/0002aa86b6ccb056ff20a04e96bc00?jumpto=comment

https://developers.weixin.qq.com/community/develop/doc/00042e3ef54940ce8520e38db61801文章來源地址http://www.zghlxwxcb.cn/news/detail-659171.html

到了這里,關(guān)于微信小程序中pdf的上傳、下載及excel導出的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • 【微信小程序】導出Excel文件

    在安卓機上能正常預覽文件,ios上出現(xiàn) “OfficeImportErrorDomain”錯誤912 。此時文件已經(jīng)保存到了手機,點擊右上角三個點用其他方式打開就能看到正常的文件內(nèi)容,在ios上預覽出現(xiàn)了問題。

    2024年02月14日
    瀏覽(21)
  • 微信小程序?qū)雽С龅絜xcel

    補充在最前面:導入不一定用這么復雜的,比如下面的思路就是,把數(shù)據(jù)復制到粘貼板,然后從粘貼板上取數(shù)據(jù),數(shù)據(jù)處理完成后,可以導入云數(shù)據(jù)庫,也可以導出到站貼板。下面這段看起來有點亂。主要是處理省市縣鎮(zhèn)村 5級,把表格數(shù)據(jù)轉(zhuǎn)換成json數(shù)據(jù),一開始用導入exc

    2024年02月09日
    瀏覽(29)
  • uniapp - 微信小程序平臺實現(xiàn)預覽 office 文件及保存下載到本地功能,將word/excel/ppt/pdf等文件在小程序內(nèi)進行預覽,用戶可以保存和轉(zhuǎn)發(fā)給好友進行下載到手機(一鍵復制運行)

    在uniapp微信小程序開發(fā)中,預覽文件、下載文件并保存到手機本地功能(支持office全套word/pdf/ppt/excel等),兼容安卓和蘋果端非常好用, 本文有2種方案,愿意用哪個就用哪個,都有示例代碼和詳細說明。

    2024年02月08日
    瀏覽(101)
  • uniapp 微信小程序?qū)С鰁xcel功能實現(xiàn)

    需要用到xlsx.core.min.js的js庫,以實現(xiàn)導出excel。 下載鏈接: SheetJS:?https://github.com/SheetJS/sheetjs 找到dist目錄下,xlsx.core.min.js文件,將它復制到你項目的/common/js/目錄下。 1、導入js庫; 2、編輯導出數(shù)據(jù)。 ?3、利用js庫導出excel。 這樣就可以了。

    2024年03月21日
    瀏覽(21)
  • 微信小程序/H5(UniApp)導入/導出excel文件

    XLSX.JS 鏈接:https://github.com/SheetJS/sheetjs 下載dist目錄下的xlsx.mini.min.js即可(根據(jù)開發(fā)需求可下載其他版本) mini版本只支持xlsx不支持xls哦,需要支持xls的話要下載完整版。 Uniapp可以將js文件放在@/common/js/目錄下 日期 事項 支出 2023-01-01 吃飯 300.00 2023-01-02 喝奶茶 28.00 2023-01-03

    2024年02月09日
    瀏覽(21)
  • 前端實現(xiàn)微信小程序JSON數(shù)據(jù)導出Excel表

    最近做微信小程序相關(guān)項目需要將數(shù)據(jù)導出為excel形式,在網(wǎng)上查了許多資料來實現(xiàn)這個功能,以下是我使用的方法,特此記錄一下,以便之后使用。 解決方法:使用sheetJS代碼插件實現(xiàn) github地址:https://github.com/SheetJS/sheetjs 下載地址:https://cdn.sheetjs.com/ 代碼如下,具體使用

    2024年01月17日
    瀏覽(16)
  • react-前端excel 文件/PDF文件 導入 --導出,照片上傳

    react-前端excel 文件/PDF文件 導入 --導出,照片上傳

    需要了解,new FormData() --上傳時,將內(nèi)容轉(zhuǎn)為文件流 ? ? ? ? ? ? ? ? ? FormData提供一種表示表單數(shù)據(jù)的鍵值對的構(gòu)造方式,實現(xiàn)表單數(shù)據(jù)的序列化,從而減少表單元素的拼接,提高工作效率 ? ? ? ? ? ? ? ? ?new FileReader()--base64壓縮,目前不了解 一、excel文件導出 ? ? ?三

    2023年04月08日
    瀏覽(24)
  • 微信小程序查看word,excel,ppt以及pdf文件(文檔)

    微信小程序查看word,excel,ppt以及pdf文件(文檔)

    ?博主介紹: 本人專注于Android/java/數(shù)據(jù)庫/微信小程序技術(shù)領(lǐng)域的開發(fā),以及有好幾年的計算機畢業(yè)設(shè)計方面的實戰(zhàn)開發(fā)經(jīng)驗和技術(shù)積累;尤其是在安卓(Android)的app的開發(fā)和微信小程序的開發(fā),很是熟悉和了解;本人也是多年的Android開發(fā)人員;希望我發(fā)布的此篇文件可以幫

    2024年02月07日
    瀏覽(121)
  • 微信小程序?qū)⒔涌诜祷氐奈募黝A覽導出Excel文件并轉(zhuǎn)發(fā)

    微信小程序?qū)⒔涌诜祷氐奈募黝A覽導出Excel文件并轉(zhuǎn)發(fā)

    把接口url替換就可以用了 效果

    2024年02月15日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包