A
A
Andrey Sobolev2020-04-16 10:37:49
JavaScript
Andrey Sobolev, 2020-04-16 10:37:49

How to extract data from the clipboard when copying Excel cells?

The situation is this. Let's say we copy 2 selected cells in Excel (one name, another number). If you press insert in Excel, it understands that these are 2 different cells and inserts them into 2 cells.
Is it possible to implement a button on the page, in which data will be inserted into 2 inputs separately (1 input - the first cell, 2 - the second)? Where to find this data via JS?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AUser0, 2020-04-16
@andrufka46rus

Copy these two cells and paste into a simple text editor (like Notepad). And you will see that the text will be in the form of two lines, separated by tabs \t . Accordingly, when pasting the copied on your page, you can break the pasted by the tab character, and shove the parts of the line into the necessary inputs ...
This is elementary, Watson!

H
hzzzzl, 2020-04-16
@hzzzzl

within one page (one JS script), which you will not reload, most likely you can twist it somehow

document.addEventListener('copy', (e) => {
    // тут можно поймать ctrl+c 
    // и например записать значения инпутов в переменную / сторадж
});

document.addEventListener('paste', (e) => {
    // а тут ctrl+v
});

UPD
when copying, you can overwrite the buffer
document.addEventListener('copy', function(e){
  e.clipboardData.setData('text/plain', 'ничего ты не скопируешь');
  e.preventDefault(); 
});

here, in theory, you can put a string in your format here, and then you can copy back and forth within the site / web application, even restarting the browser
https://caniuse.com/#feat=clipboard

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question