augusto.pellis Posted April 10, 2020 Share Posted April 10, 2020 Good morning, could anyone suggest me how to, after having copied cells content from an xls file, paste it to a uni grid, having each excel cell value pasted into a unigrid cell? Thanks for your time Augusto Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 10, 2020 Share Posted April 10, 2020 Hello, Need to analyze. Quote Link to comment Share on other sites More sharing options...
augusto.pellis Posted April 10, 2020 Author Share Posted April 10, 2020 Thank you for your efforts! Augusto Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 10, 2020 Share Posted April 10, 2020 6 hours ago, augusto.pellis said: could anyone suggest me how to, after having copied cells content from an xls file, paste it to a uni grid, having each excel cell value pasted into a unigrid cell? Hello, I will give you the sequence of actions (one of the possible solutions of course, also you should think about error handling)... 1. UniDBGrid1.ClientEvents.ExtEvents -> function keydown(e, t, eOpts) { var grid = this.grid; grid.arr = []; grid.arrJSON = []; var models = this.grid.getStore().getRange(); if (e.ctrlKey && e.keyCode == 86) { navigator.clipboard.readText() .then(text => { grid.arr = text.split("\n"); if (grid.arr.length == 1) { grid.arr = text.split("\n"); } else { grid.arr.splice(-1, 1); } grid.arr.forEach(function(a, r) { a.split('\t').forEach(function(b, c) { console.log(b, r, c); try { grid.arrJSON.push({ "r": grid.uniRow + r, "c": grid.uniCol + c, "v": b }); //models[grid.uniRow + r].set(String(grid.uniCol + c), b) } catch (err) {} }) }); ajaxRequest(grid, 'copypaste', ['val='+JSON.stringify(grid.arrJSON)]); }) .catch(err => { console.error('Failed to read clipboard contents: ', err); }); } } 2. Uses ..., XSuperJSON, XSuperObject; https://github.com/onryldz/x-superobject 3. type TRec = record R: Integer; C: Integer; V: string; end; 4. UniDBGrid1.OnAjaxEvent procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); var Test: TArray<TRec>; S: String; I: Integer; begin if EventName = 'copypaste' then begin S := Params.Values['val']; Test := TJSON.Parse<TArray<TRec>>(S); with (Sender as TUniDBGrid) do begin BeginUpdate; for I := 0 to High(Test) do begin DataSource.DataSet.RecNo := Test[I].R+1; DataSource.DataSet.Edit; DataSource.DataSet.Fields[Test[I].C].AsString := Test[I].V; DataSource.DataSet.Post; end; EndUpdate; end; end; end; Try... 1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 10, 2020 Share Posted April 10, 2020 And I tested it on Chrome... Quote Link to comment Share on other sites More sharing options...
augusto.pellis Posted April 11, 2020 Author Share Posted April 11, 2020 Impressive contribution, sir! I will test your code as soon as possible,. In the meantime please accept my best regards! Augusto 1 Quote Link to comment Share on other sites More sharing options...
augusto.pellis Posted April 28, 2020 Author Share Posted April 28, 2020 It works like a charm! Respect. Augusto Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.