Page 1 of 1

Adjusting alignment in Excel

Posted: Wed Apr 06, 2016 9:33 am
by driessen
Hello,

How can I adjust the alignment of a cel, some cells, columns or rows in FWH for Excel?

Thanks.

Re: Adjusting alignment in Excel

Posted: Wed Apr 06, 2016 11:00 am
by bpd2000

Code: Select all

#include "FiveWin.ch"

function Main()

   local oExcel := CreateObject( "excel.application" )
   local oBook  := oExcel:Workbooks:Add()
   local oSheet := oBook:Worksheets( 1 ) 

   oSheet:Range( "A1" ):Value = "Last Name"
   oSheet:Range( "B1" ):Value = "First Name"
   oSheet:Range( "A1:B1" ):Font:Bold = .T.
   
   oSheet:Range( "A2" ):Value = "Doe"
   oSheet:Range( "B2" ):Value = "John"

   oSheet:Cells(5, 1):Value := "Left Alignment"
   oSheet:Cells(6, 1):Value := "Cente Alignment"
   oSheet:Cells(7, 1):Value := "Right Alignment"
 
 //&& 4 for Right Alignment, 3 for Center and 2 for Left  
   
   oSheet:Cells(5, 1):HorizontalAlignment := 4 
   oSheet:Cells(6, 1):HorizontalAlignment := 3  
   oSheet:Cells(7, 1):HorizontalAlignment := 2  
   
   oBook:SaveAs( "C:\fwh\samples\Book1.xls" ) 
   oExcel:Visible = .T.

   // oExcel:Quit() 

   MsgInfo( "ok" )

return nil
   
   

Re: Adjusting alignment in Excel

Posted: Wed Apr 06, 2016 11:49 am
by driessen
Thanks a lot for your help.

Re: Adjusting alignment in Excel

Posted: Thu Apr 07, 2016 3:03 am
by cdmmaui
Hello,

You can define as well:

# DEFINE xlHAlignGeneral 1
# DEFINE xlHAlignLeft -4131
# DEFINE xlHAlignCenter -4108
# DEFINE xlHAlignRight -4152
# DEFINE xlHAlignJustify -4130
# DEFINE xlVAlignBottom -4107
# DEFINE xlVAlignTop -4160
# DEFINE xlVAlignCenter -4108
# DEFINE xlVAlignJustify -4130

oAs:Range ('A1:O1'):Merge()
oAs:Cells (nRow, 1):HorizontalAlignment = xlHAlignCenter
oAs:Cells (nRow, 1):Font:Bold := .T.
oAs:Cells (nRow, 1):Font:Size := 12
oAs:Cells (nRow, 1):Value := PA[11]

// Shading...
oAs:Range ('A'+LTRIM(STR(nRow))+':O'+LTRIM(STR(nRow))):Interior:ColorIndex = 17

here is website for color codes: http://dmcritchie.mvps.org/excel/colors.htm

// Alignment...
oAs:Range ('C'+LTRIM(STR(nRow))+':C65536'):HorizontalAlignment = xlHAlignCenter
oAs:Range ('M'+LTRIM(STR(nRow))+':M65536'):HorizontalAlignment = xlHAlignRight

oAs:Range ('K'+LTRIM(STR(nRow))+':K65536'):NumberFormat = '###,###,###.00'