Adjusting alignment in Excel

Post Reply
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Adjusting alignment in Excel

Post by driessen »

Hello,

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

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
bpd2000
Posts: 153
Joined: Tue Aug 05, 2014 9:48 am
Location: India

Re: Adjusting alignment in Excel

Post 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
   
   
Regards, Greetings

Try FWH. You will enjoy it's simplicity and power.!
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Adjusting alignment in Excel

Post by driessen »

Thanks a lot for your help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Re: Adjusting alignment in Excel

Post 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'
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Post Reply