Creating reports or spreadsheets from existing templates speeds up development. Starting with 4D v19 R4, copy and paste actions can now be performed using code that copies a range of cells from another location (including other areas).
Move or copy a block of cells.
The VP MOVE CELLS command allows you to copy/cut and paste a range of cells to another location, even between two areas:
// Starting range
$rangeFrom:=VP Cells("ViewProArea1"; 0; 0; 2; 7)
// First cell of the destination range
$rangeTo:=VP Cell("ViewProArea2"; 2; 0)
VP MOVE CELLS($rangeFrom; $rangeTo; New object("copy"; True))
copy paste over an object
Another way to copy a range is to copy it to an object with the VP Copy to object command, for example, to save it in your database:
$template:=ds.Templates.new()
$template.VP:=VP Copy to object($rangeFrom)
$template.save()
So you can paste the contents, styles and formulas stored in the object when you need it with the VP PASTE FROM OBJECT command:
$template:=ds.Templates.get($id)
VP PASTE FROM OBJECT($rangeTo; $template.VP)
Whichever solution you use, it’s essential to be aware of the possibilities: relative cell references might change when you move or copy a formula. Learn more about this feature on the documentation center.