Paste content from Excel to Chrome Paste content from Excel to Chrome google-chrome google-chrome

Paste content from Excel to Chrome


All you need is to add a CR, carriage return, symbol (it is the default line break style in MS Office documents). Also, String#split method does not require the use of the g global modifier with the regex passed as an argument, as this method behavior is like that by default.

Use

const separators = [',', ';', '\\(', '\\)', '\\*', '/', ':', '\\?', '\n', '\r'];return data.split(new RegExp(separators.join('|'))).map(d => d.trim());


Okay, I got this working.

    /*     * Chrome and Safari seem to treat new lines pasted from Excel like an Enter press.     * Enter has a CharCode of 13, so checking if this string contains CharCode 13 is sufficient.     * If the string contains a CharCode 13, we split the string after every CharCode 13.     * And kids, that's how I made pasting from Excel possible (HIMYM voice)     */    const enterCharCode = String.fromCharCode(13);    if (data.includes(enterCharCode)) {        return data.split(enterCharCode);    }    const separators = [',', ';', '\\(', '\\)', '\\*', '/', ':', '\\?', '\n'];    return data.split(new RegExp(separators.join('|'), 'g')).map(d => d.trim());