Comments (7)
Firstly, please excuse the bad code below but it gives the basic idea of how to fix this. It works in all cases except where the column with the Alt+Enter's in it is the last column in each row - I haven't worked out how to fix it for that case but our users won't be doing that so it's fine for me. Basically, I just changed the parsePasteInput function to not split rows on /n where the /n is in a column produced with text wrap and so bounded with "". Instead of splitting rows for these /n I just post process these after row splitting to put the /n back. Below gives the idea (again please excuse the bad code).
parsePasteInput: function (input) {
var rows, r, rlen;
//replace any \n instances in input bounded by "" with \\n so as not to split to new row then replace back after split
//this stops EXCEL based pastes where data has returns within cells from being split into rows
//read all chars in input and from wherever a pattern of \t" or \n" or if start of input and " then replace all occurences of \n
//until next "\t or "\n or end of input
var input3 = input.split(/\t/g);
var input2 = "";
for (var c = 0, clen = input3.length; c < clen; c++)
{
if ( input3[c][0] == '\"' && input3[c][input3[c].length-1] == '\"')
{
input2 = input2 + input3[c].substring(0, input3[c].length-1).substring(1).replace(/\n/g, '\\n') + '\t';
}
else
{
input2 = input2 + input3[c] + '\t';
}
}
rows = input2.split(/\n/g);
if (rows.length > 1 && rows[rows.length - 1] === '') {
rows.pop();
}
for (r = 0, rlen = rows.length; r < rlen; r++) {
// replace new lines within cells back after row splits
rows[r] = rows[r].replace(/\\n/g, "\n");
rows[r] = rows[r].split("\t");
}
return rows;
}
from handsontable.
my comments in the the last posting were a bit misleading so re-posting the code here:
parsePasteInput: function (input) {
var rows, r, rlen;
//replace any \n instances in input bounded by \t column indicators and "" with \\n so as not to split to new row then replace back after split
//this stops EXCEL based pastes where data has returns within cells from being split into rows
var input3 = input.split(/\t/g);
var input2 = "";
for (var c = 0, clen = input3.length; c < clen; c++)
{
if ( input3[c][0] == '\"' && input3[c][input3[c].length-1] == '\"')
{
input2 = input2 + input3[c].substring(0, input3[c].length-1).substring(1).replace(/\n/g, '\\n') + '\t';
}
else
{
input2 = input2 + input3[c] + '\t';
}
}
rows = input2.split(/\n/g);
if (rows.length > 1 && rows[rows.length - 1] === '') {
rows.pop();
}
for (r = 0, rlen = rows.length; r < rlen; r++) {
// replace new lines within cells back after row splits
rows[r] = rows[r].replace(/\\n/g, "\n");
rows[r] = rows[r].split("\t");
}
return rows;
}
from handsontable.
Thanks vignette, I will look into it on Monday, if you allow.
from handsontable.
Thanks warpech, any time you can spare to look at this would be great.
from handsontable.
Thanks for the report and proposal solution. I found a lot of quirks about parsing CSV/TSV values that can come from Excel, LibreOffice or Google Docs. By the method of trial and error I found a function that seems to do the job of parsing input data very well. Could you please check again? I am at your service :)
from handsontable.
Great work, I think you've nailed the solution! We will proceed to use this to implement a system for lodging contractor data with our organisation. After development and testing, before release (November) I will organise for a company donation. For now, I made a small personal donation myself of $50 because you've certainly saved me a lot more than that, even for an alpha concept prototype!
from handsontable.
Thank you, I appreciate it! Please let me know if you need some special features.
from handsontable.
Related Issues (20)
- [Bug]: Removing value in numeric cell results in empty string HOT 3
- [Bug]: If I update to v14.1. 0 with npm i @ Handsontable/vue, there will be over a thousand such errors. HOT 3
- [Bug]: Cannot move multi columns which are selected by `ctrl + click` HOT 1
- [Bug]: When there are many options, there is a bug when filtering in the drop-down menu. HOT 3
- [Bug]: Unable to pass "type" to a HotColumn component in react. HOT 5
- [Bug]: Custom border misaligns rows HOT 4
- [Bug]: .manualColumnResizer goes out of position inside scaled parent element HOT 1
- [Bug]: cellMeta reseted when updating data HOT 12
- [Bug]: When first cell of selection is a checkbox, it prevents BACKSPACE or DELETE buttons actions HOT 1
- [Bug]: `AutoColumnSize` plugin gets disabled when `colWidths` is set HOT 2
- [Bug]: getSelected row/col start and row/col end incorrect when copying data HOT 3
- [Bug]: Different scrolling experience with scrollbar vs. with touchpad HOT 1
- [Bug]: The first character automatically converts to an English letter in Japanese HOT 17
- [Bug]: Styling issue when scrolling to up with renderAllRows=false (flickering) HOT 3
- [Bug]: `cmd + zยด not working on German keyboard HOT 3
- [Bug]: when i use 'custom renderer as a component'. Sometimes, the Component Elements will be automatically cleared HOT 5
- Seperate doc examples
- Docs migration / Algolia
- Improved code preview
- Smooth UX
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handsontable.