Browse Source

表格复制出数据的转文本

Karsa 11 months ago
parent
commit
81983481bd

+ 12 - 7
src/utils/svgToblob.js

@@ -46,11 +46,16 @@ export const svgToBase64 = (svg) => {
 
 /* 不受粘贴板对象影响的粘贴 */
 export function copyFit(value) {
-  const input = document.createElement('input')
-  input.setAttribute('readonly','readonly')
-  input.value = value
-  document.body.appendChild(input)
-  input.select();
-  document.execCommand('copy');
-  document.body.removeChild(input);
+  if(navigator.clipboard) {
+    navigator.clipboard.writeText(value)
+  }else {
+    const input = document.createElement('input')
+    input.setAttribute('readonly','readonly')
+    input.value = value
+    document.body.appendChild(input)
+    input.select();
+    document.execCommand('copy');
+    document.body.removeChild(input);
+  }
+
 }

+ 17 - 0
src/views/datasheet_manage/components/SheetExcel.vue

@@ -4,6 +4,7 @@
 </template>
 
 <script>
+import { copyFit } from '@/utils/svgToblob.js';
 import { initSheet } from '../common/option';
 export default {
   props: {
@@ -36,6 +37,7 @@ export default {
     copyDisable(e){
       // 变向的禁止复制
       // console.log(e.target.value && e.target.value.indexOf('lucksheet'));
+      this.copyData()
       if(!this.limit.disabled) return
       if(e.target.value && e.target.value.indexOf('lucksheet')){
         luckysheet.enterEditMode();
@@ -43,6 +45,21 @@ export default {
         return false
       }
     },
+
+    copyData() {
+      let rangeArr = luckysheet.getRangeArray('twoDimensional');
+      let str = ''
+      rangeArr.forEach(item => {
+        let row = ''
+        item.forEach((cell,index) => {
+          row+= `${index!==0?'\t':''}${cell||''}`
+        })
+        str+=`${row}\n`
+      });
+      
+      copyFit(str)
+    },
+
     updateEmit(){
       this.$emit("updated")
     }

+ 7 - 5
src/views/datasheet_manage/customAnalysis/components/createTargetForm.vue

@@ -188,7 +188,7 @@ export default {
           unit:'',
         }
         
-        this.setRangeShow(['A1','A1'])
+        luckysheet.setRangeShow(['A1','A1'])
       }
     },
 
@@ -218,13 +218,15 @@ export default {
 
     /* 处理超过表格行无法显示选区的问题 超过后截止到最后一行 */
     filterFormula(item,rowLen) {
-      let celArr = item.split(':');
-      let numStr = celArr[1].replace(/[^0-9]/ig,""); 
-      let letterStr = celArr[1].replace(/[^a-z]+/ig,"");
+      let cellArr = item.split(':');
+      if(!cellArr[1]) return item
+
+      let numStr = cellArr[1].replace(/[^0-9]/ig,""); 
+      let letterStr = cellArr[1].replace(/[^a-z]+/ig,"");
       
       let lastNum = Number(numStr) > rowLen ? rowLen : Number(numStr);
       
-      return `${celArr[0]}:${letterStr}${lastNum}`
+      return `${cellArr[0]}:${letterStr}${lastNum}`
     },
 
     /* 解析公式 */

+ 1 - 5
src/views/ppt_manage/newVersion/components/formatPage/mixins.js

@@ -288,11 +288,7 @@ export default {
           const chartTitle = this.$store.state.ppt.chartInfoMap[chartId].chartTitle
           console.log('chart_title',chartTitle)
           try{
-            if(navigator.clipboard) { //兼容禁止粘贴板的场景
-              await navigator.clipboard.writeText(chartTitle)
-            }else {
-              copyFit(chartTitle)
-            }
+            copyFit(chartTitle)
             this.$message.success('复制成功')
           }catch(err){
             this.$message.error('复制失败')