KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: VP Copy and Paste With Cell Sizes
PRODUCT: 4D View Pro | VERSION: 19 | PLATFORM: Mac & Win
Published On: July 5, 2022

4D View Pro allows a copy and paste feature to be implemented programatically using the VP Copy to object and VP PASTE FROM OBJECT commands. The VP Copy to object command, targets a VP Range and copies the data and styles of the cells. Then VP PASTE FROM OBJECT will then allow the resulting object from the copy, to be pasted in a specified range of new cells.

These two commands however, will not transfer the sizes of the cells. To apply the sizing of the cells, the commands VP Get row attributes and VP Get column attributes can be used to get a collection of properties from the rows and columns of a range. The properties can then be applied to each new row and column of the target range to apply the same height and width to the cells.

Below is an example of copying all the data from one vp document to a new vp document including the cell dimensions:

$sheetVPRange:=VP All("ViewProArea")
$sheetObj:=VP Copy to object($sheetVPRange)
$columnAttrC:=VP Get column attributes($sheetVPRange)
$rowAttrC:=VP Get row attributes($sheetVPRange)

VP NEW DOCUMENT("ViewProArea2")
VP PASTE FROM OBJECT(VP All("ViewProArea2"); $sheetObj; vk clipboard options values and formatting)

For ($i; 0; $columnAttrC.length-1)
  VP SET COLUMN ATTRIBUTES(VP Cell("ViewProArea2"; $i; 0); $columnAttrC[$i])
End for

For ($i; 0; $rowAttrC.length-1)
  VP SET ROW ATTRIBUTES(VP Cell("ViewProArea2"; 0; $i); $rowAttrC[$i])
End for


The result of the code above will not only copy the data from one document to another, but will also copy the dimensions of each row and column. Leaving out the application of the column and row attributes will keep the default dimensions of a new VP document instead.