2017-12-23 19 views
0

거대한 셀 값을 가진 테이블이 있습니다. 이 값은 테이블을 가볍고 빠르게 만들기 위해 100 개의 기호로 잘립니다. 셀 호버에서는 CopyButton을 보여줍니다. CopyButton에서 function copyToClipboard를 호출하고 거기에 셀 값을 전달합니다.여분의 큰 값을 클립 보드로 복사하는 방법은 무엇입니까?

복사하는 동안 1MB를 초과하는 값이 브라우저에서 멈추고 클립 보드의 값이 바뀌지 않습니다.

const copyToClipboard = text => { 
    const textField = document.createElement('textarea') 
    textField.innerText = text 
    document.body.appendChild(textField) 
    textField.select() 
    document.execCommand('copy') 
    textField.remove() 
} 

큰 값으로 작동 할 수있는 클립 보드 솔루션이 있습니까?

답변

0

내 해결 방법 : 경우

값이 나는 사용자의 브라우저에 파일을 던져보다 더 큰 150K 상징이다. 기능을 참조하십시오 downloadTextDocument.

const downloadTextDocument = (documentValue, filename) => { 
    const blob = new File([documentValue], filename, { type: 'text/plain' }) 
    const downloadUrl = window.URL.createObjectURL(blob); 
    download(downloadUrl, filename); 
    window.URL.revokeObjectURL(downloadUrl); // cleanup 
} 

const download = (url, filename) => { 
    const tempLink = document.createElement('a'); 
    tempLink.href = url; 
    tempLink.setAttribute('download', filename) 
    document.body.appendChild(tempLink); 
    tempLink.click(); 
    document.body.removeChild(tempLink); 
}