1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| #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
Local ix,ox
Rand(-1)
Select order_id, cust_id, emp_id, to_name,;
to_address, to_city, to_region, postalcode,;
to_country, ;
ship_via, Date()+10-Int(Rand()*20) As due_date ;
FROM (_samples+'data\orders') ;
INTO Array SampleData
* Add headers to array
Dimension SampleData[ALEN(SampleData,1)+1,ALEN(SampleData,2)]
Ains(SampleData,1)
For ix=1 To Alen(SampleData,2)
SampleData[1,m.ix] = 'Sample_'+Chr(Asc('A')-1+m.ix)
Endfor
ox = Createobject('Excel.Application')
With ox
.WorkBooks.Add
.Visible = .T.
With .ActiveWorkBook.ActiveSheet
Local loDataRange, loFormatRange
* Data range
loDataRange = .Range(.Cells(1,1), ;
.Cells(Alen(SampleData,1),Alen(SampleData,2)))
* Format range - start at row 2 skipping header
loFormatRange = .Range(.Cells(2,1), ;
.Cells(Alen(SampleData,1),Alen(SampleData,2)))
Endwith
* Put the data in Excel
loDataRange.Value = getArrayRef('SampleData')
* Conditional format
With loFormatRange
.FormatConditions.Delete
.FormatConditions.Add(xlExpression,, '=$K1 < TODAY()')
.FormatConditions.Add(xlExpression,, '=$K1 = TODAY()')
.FormatConditions.Add(xlExpression,, '=$K1 > TODAY()')
With .FormatConditions(1)
.Font.Bold = 1
.Font.Italic = 1
.Font.Color = 0xFFFFFF && white
.Interior.Color = 0x0000FF && red
Endwith
With .FormatConditions(2)
With .Font
.Bold = 1
.Color = 0 && black
Endwith
.Interior.Color = 0x00FFFF && yellow
Endwith
With .FormatConditions(3)
.Font.Bold = 0
.Font.Color = 0 && black
.Interior.Color = 0xFFFFFF && white
Endwith
Endwith
Endwith
Function getArrayRef(tcArrayName)
Return @&tcArrayName |