KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: 4D View Pro Cell Alignment
PRODUCT: 4D | VERSION: 17 R | PLATFORM: Mac & Win
Published On: May 10, 2019
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

It is possible to set the alignment of text in specific cells of a 4D View Pro area.

Below is a methods that will allow the alignment to be set on the specific cell or range of cells.

// Method: VP_TextAlign
// Description
// Prints a sheet of a VP Area
//
// Parameters
// $1 - Text VP area object name
// $2 - Alignment: -1 = Left
// 0 = Default/General
// 1 = Center
// 2 = Right
// $3 - Row number
// $4 - Column number
// $5 - Row Count
// $6 - Column count
//
// Note: If both the row number and row count are -1
// then the entire column is selected and
// vice-versa for the oposite.
// ----------------------------------------------------

C_TEXT($1;$vpArea_t)
C_LONGINT($2;$align_l)
C_LONGINT($3;$row_l)
C_LONGINT($4;$col_l)
C_LONGINT($5;$rowCount_l)
C_LONGINT($6;$colCount_l)

C_TEXT($jsCode_t)
C_TEXT($res_t)

If (Count parameters>3)
   $vpArea_t:=$1
   $align_l:=$2
   $row_l:=$3
   $col_l:=$4
  
   $jsCode_t:="spread.getActiveSheet()."
  
   If (Count parameters=6)
  
     $rowCount_l:=$5
     $colCount_l:=$6
  
     $jsCode_t:=$jsCode_t+"getRange("
     $jsCode_t:=$jsCode_t+String($row_l)+","
     $jsCode_t:=$jsCode_t+String($col_l)+","
     $jsCode_t:=$jsCode_t+String($rowCount_l)+","
     $jsCode_t:=$jsCode_t+String($colCount_l)+")"
  
   Else
  
     $jsCode_t:=$jsCode_t+"getCell("
     $jsCode_t:=$jsCode_t+String($row_l)+","
     $jsCode_t:=$jsCode_t+String($col_l)+")"
   End if
  
   $jsCode_t:=$jsCode_t+".hAlign(GC.Spread.Sheets.HorizontalAlign."
  
   Case of
   : ($align_l=-1)
     $jsCode_t:=$jsCode_t+"left);"
   : ($align_l=0)
     $jsCode_t:=$jsCode_t+"general);"
   : ($align_l=1)
     $jsCode_t:=$jsCode_t+"center);"
   : ($align_l=2)
     $jsCode_t:=$jsCode_t+"right);"
   End case
  
   $res_t:=WA Evaluate JavaScript(*;$vpArea_t;$jsCode_t)
  
End if


Examples of using the method

Setting alignment of 0,0 cell to Left by passing -1 and since a single cell is targeted the optional row count and column count can be omitted:
VP_TextAlign ("vpAreaName";-1;0;0)


Setting alignment of range starting from 1,2 to 4,5 cell to Default by passing 0 and the inital row and collumn position to 1 and 2 and a count of 4 for row count and column column count each to reach 4 and 5 respectively
VP_TextAlign ("vpAreaName";0;1;2;4;4)


Setting alignment of the entire columns of 2 to 4 to Center by passing 1 and setting the row position and row count to -1 while defining the column's position and count.
VP_TextAlign ("vpAreaName";1;-1;2;-1;3)


Setting alignment of the entire rows of 6 to 8 to Right
VP_TextAlign ("vpAreaName";2;6;-1;3;-1)