Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating excel multiple row selection

I am trying to solve copy pasting a column with values from excel into a textarea in my web app.

The user will simply select row values in a column, e.g. the excel table looks like (the user will not select the header)

 -----
|Code |
 -----
|  1  |
 -----
|  2  |
 -----
|  3  |
 -----
|  4  |
 -----
|  5  |
 -----

When I paste this into a text area, it pastes in with the spaces, e.g.

 --------------------------------------------
|1                                           |
|2                                           |
|3                                           |
|4                                           |
|5                                           |
|                                            |
 --------------------------------------------

But when I post this text area to the controller, receiving it like so:

public ActionResult Search(string searchTerms)
{
    //`searchTerms` = "12345"
    ...omitted for brevity...
}

This is a problem, as the codes represent separate object.

What would be the easiest way I could modify this so I can receive some sort of separator? Keeping in mind the user will just want to hit ctrl+v and have the entire list entered. Simple modifications to the excel spreadsheet to have the list separated on copy or alternative excel type solution would also be acceptable.

like image 453
baron Avatar asked Nov 14 '22 18:11

baron


1 Answers

You could insert the separators when the text is pasted into the textarea. With something like the following

$("textarea").change(function() {
    $(this).val($(this).val().split('\n').join(','));
});

Example: http://jsfiddle.net/ADwYg/

like image 147
Josh Avatar answered Dec 29 '22 08:12

Josh