#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Paste from excel


    Hi

    I am trying to provide an easy import from excel feature to the user. They can copy paste some values from the excel template to the webinterface. However when excel has a multiline cell (I mean a cell with a break (or multiple) in it, not merged cells).

    Example:
    Code:
    Col1            Col2
    Test1           Res1
    Test2           Res2a
                       Res2b
    Test3           Res3
    Test4           Res4a
                       Res4b
                       Res4c
    (The multiline can be an unknown amount of lines)


    I want to import these and add them to a form with a textarea per field so 2 fields per row.

    Now i can do this for the singleline cells, however how can I use this for the multiline?
    I am thinking for something in the split, however I can not figure out what. I tried some regexpressions, but I', not so well known with these.

    jQuery code used:
    Code:
    var data = $("#import_text").val();                    
     var arr = data.split( /[\r\n]/g );
          $.each(arr, function(i){
                row = arr[i].split( /\t/ );
                col1 = $.trim(row[0]);
                col2 = $.trim(row[1]);
                //Set values and such
           }
    });
    When copying from excel the export is
    Test1 (tab) Res1 (break)
    Test2 (tab) "Res2a (break)
    Res2b"(break)
    Test3 (tab) Res3 (break)
    Test4 (tab) "Res4a (break)
    Res4b (break)
    Res4c"(break)



    I think I will need a regex that can convert the breaks within the quoted text, however I don't know how. Can you help out?
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    What value do you get in your application if the Excel field contains a literal "?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0
    That indeed will screw things up, however if I recall correctly only singlequotes are used

IMN logo majestic logo threadwatch logo seochat tools logo