Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy paste from excel #95

Closed
MathiasLund opened this issue Jul 28, 2016 · 7 comments
Closed

copy paste from excel #95

MathiasLund opened this issue Jul 28, 2016 · 7 comments

Comments

@MathiasLund
Copy link

Hi there,
great repo!!

Is it possible to make a pasteSplit functionality that also handles copy-paste from Excel?
I've tried different regex's but I can't seem to make it work.

this is my code:

<ReactTagsInput addOnPaste={true} pasteSplit={ data => { return data .replace(/[\n\r]/g, ' ') .split(' ') .map(d => d.trim()) }} ref="tags" value={this.state.keywords} onChange={this.handleChange} />

and this is my dummy data from excel:
image

but doing this regex: [\n\r] splits up all of the words between whitespace.
So for instance: "danish pastry", becomes "danish" and "pastry".

any ideas? thanks! :)

@wildeyes
Copy link

you should look for \t in your regex.

@jonicious
Copy link
Contributor

jonicious commented Dec 13, 2016

I am currently dealing with the same issue. Adding \t to my list of separators did not work. Currently my code looks like this:

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

Help really appreciated!

@wildeyes
Copy link

@jonicious try pasting the data into an editor that allows you to see all chars, even invisible ones (like sublime text) to see what the seperators are.

@jonicious
Copy link
Contributor

@MathiasLund I got it working like this: http://stackoverflow.com/a/42008610/3276759 cc @wildeyes

@jonicious
Copy link
Contributor

This solution is better: http://stackoverflow.com/a/42008826/3276759

@olahol
Copy link
Owner

olahol commented Feb 11, 2017

Added your answer to FAQ @jonicious. Thank you.

@olahol olahol closed this as completed Feb 11, 2017
@jonicious
Copy link
Contributor

@olahol Thanks. Opened a PR for improving the answer to give credit to the person who solved the problem on Stack Overflow. See #129. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants