; #FUNCTION# ====================================================================================================================
; Name...........: _ExcelHorizontalAlignSet
; Description ...: Set the horizontal alignment of each cell in a range.
; Syntax.........: _ExcelHorizontalAlignSet($oExcel, $sRangeOrRowStart[, $iColStart = 1[, $iRowEnd = 1[, $iColEnd = 1[, $sHorizAlign = "left"]]]])
; Parameters ....: $oExcel - An Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
; $sRangeOrRowStart - Either an A1 range, or an integer row number to start from if using R1C1
; $iColStart - The starting column for the number format(left) (default=1)
; $iRowEnd - The ending row for the number format (bottom) (default=1)
; $iColEnd - The ending column for the number format (right) (default=1)
; $sHorizAlign - Horizontal alignment ("left"|"center"|"right") (default="left")
; Return values .: On Success - Returns 1
; On Failure - Returns 0 and sets @error on errors:
; |@error=1 - Specified object does not exist
; |@error=2 - Starting row or column invalid
; |@extended=0 - Starting row invalid
; |@extended=1 - Starting column invalid
; |@error=3 - Ending row or column invalid
; |@extended=0 - Ending row invalid
; |@extended=1 - Ending column invalid
; Author ........: SEO <locodarwin at yahoo dot com>
; Modified.......: litlmike
; Remarks .......: None
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _ExcelHorizontalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sHorizAlign = "left")
If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
If Not StringRegExp($sRangeOrRowStart, "[A-Z,a-z]", 0) Then
If $sRangeOrRowStart < 1 Then Return SetError(2, 0, 0)
If $iColStart < 1 Then Return SetError(2, 1, 0)
If $iRowEnd < $sRangeOrRowStart Then Return SetError(3, 0, 0)
If $iColEnd < $iColStart Then Return SetError(3, 1, 0)
Switch ($sHorizAlign)
Case "left"
$oExcel.Activesheet.Range($oExcel.Cells($sRangeOrRowStart, $iColStart), $oExcel.Cells($iRowEnd, $iColEnd)).HorizontalAlignment = $xlLeft
Case "center", "centre"
$oExcel.Activesheet.Range($oExcel.Cells($sRangeOrRowStart, $iColStart), $oExcel.Cells($iRowEnd, $iColEnd)).HorizontalAlignment = $xlCenter
Case "right"
$oExcel.Activesheet.Range($oExcel.Cells($sRangeOrRowStart, $iColStart), $oExcel.Cells($iRowEnd, $iColEnd)).HorizontalAlignment = $xlRight
EndSwitch
Else
Switch ($sHorizAlign)
Case "left"
$oExcel.Activesheet.Range($sRangeOrRowStart).HorizontalAlignment = $xlLeft
Case "center", "centre"
$oExcel.Activesheet.Range($sRangeOrRowStart).HorizontalAlignment = $xlCenter
Case "right"
$oExcel.Activesheet.Range($sRangeOrRowStart).HorizontalAlignment = $xlRight
EndSwitch
EndIf
Return 1
EndFunc ;==>_ExcelHorizontalAlignSet