|PIA Page with paste window and results grid|
|App Designer Page|
Local Rowset &rs = GetRowset(Scroll.GRS_TBL); Local array of string &aRows; Local array of string &aFields; &aString = CreateArray(""); &aFields = CreateArray(""); &aRows = Split(GRS_WRK.HTMLAREA, Char(10)); For &i = 1 To &aRows.Len &aFields = Split(&aRows [&i], "|"); &rs(&i).GRS_TBL.SELNUM.Value = &aFields ; &rs(&i).GRS_TBL.DESCR.Value = &aFields ; &rs.InsertRow(&rs.ActiveRowCount); End-For;
- You can obviously change the separator from | (pipe) to whatever works for you. Comma is useful when pasting from Excel.
- You will want to add some structure checking code. If you're expecting 2 fields but a user pastes 3 then you'll want to trap that.
- You may want to do some datatype validation to avoid generating PeopleCode or component processor errors.
- You could get really smart and create a button which reads data directly from the clipboard. Most browsers don't allow you to do this for security reasons but there are ways to configure browsers to trust the clipboard.
- I've been using this recently to repeatedly flush and reload data into tables on a new application I've been building. I went as far as making the table name a parameter and setting GETFIELD(n).Value rather than an explicit field name as I had numerous tables to populate.
Any other ideas or suggestions then, as usual, just post comments below.