Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel Automation - ConditionalFormat
Message
From
19/02/2004 12:11:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
19/02/2004 11:55:03
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00878775
Message ID:
00878786
Views:
24
This message has been marked as the solution to the initial question of the thread.
>Can anybody help me understand how to sucessfully access the ConditionalFormats collection from my VFP form?
>
>I'm using the following code but I keep getting the error that "the parameter is incorrect".
>
>
>lcLastCell = oExcel.ActiveCell.SpecialCells(xlLastCell).Address()
>oExcel.Range("B9:" + lcLastCell).Select
>
>oExcel.Selection.FormatConditions.Delete
> oExcel.Selection.FormatConditions.Add(xlExpression,1,"=RIGHT($B9,5)='Total'")
>
>


Andrew,
1 is xlBetween constant and it should be omitted when it's xlExpression.
ie:
lcXLS = Sys(5)+Curdir()+'Conditional.xls'
Select cust_id, Company, Contact, Title, maxordamt ;
  from customer ;
  into Cursor crsCustomer
Copy To (lcXLS) Type Xl5


#Define xlCellValue	1
#Define xlExpression	2

#Define xlBetween	1
#Define xlNotBetween	2
#Define xlEqual	3
#Define xlNotEqual	4
#Define xlGreater	5
#Define xlLess	6
#Define xlGreaterEqual	7
#Define xlLessEqual	8

lnRows = Reccount()
lnCols = Fcount()

Use In 'crsCustomer'
Use In 'customer'

oExcel = Createobject('Excel.Application')
With oExcel
  .WorkBooks.Open(lcXLS)
  .ActiveWorkbook.ActiveSheet.UsedRange.Columns.Autofit
  *ValueSample()
  ExpressionSample()
  .Visible = .T.
Endwith

Function ValueSample
lcRange = _GetChar(lnCols)+'2:'+;
  _GetChar(lnCols)+Ltrim(Str(lnRows+1)) && 1 header
With oExcel.ActiveWorkbook.ActiveSheet.Range(lcRange)
  .FormatConditions.Delete
  .FormatConditions.Add(xlCellValue, xlLess, "2000" )
  .FormatConditions.Add(xlCellValue, xlBetween, "2000", "4000" )
  With .FormatConditions(1)
    .Interior.ColorIndex = 4
  Endwith
  .FormatConditions(2).Interior.ColorIndex = 3
Endwith

Function ExpressionSample
lcRange = 'A2:'+_GetChar(lnCols)+Ltrim(Str(lnRows+1)) && 1 header
oExcel.ActiveWorkbook.ActiveSheet.Range('A2').Activate
With oExcel.ActiveWorkbook.ActiveSheet.Range(lcRange)
  .FormatConditions.Delete
  .FormatConditions.Add(xlExpression,, '=Left($D2,5)="Sales"')
  With .FormatConditions(1)
    .Font.Bold = .T.
    .Interior.ColorIndex = 4
  Endwith
Endwith

* Return A, AA, BC etc noation for nth column
Function _GetChar
Lparameters tnColumn && Convert tnvalue to Excel alpha notation
If tnColumn = 0
  Return ""
Endif
If tnColumn <= 26
  Return Chr(Asc("A")-1+tnColumn)
Else
  Return _GetChar(Int(Iif(tnColumn % 26 = 0,tnColumn - 1, tnColumn) / 26)) + ;
    _GetChar((tnColumn-1)%26+1)
Endif
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform