Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Decimal places in excel
Message
From
26/09/2006 13:49:03
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Pro
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01155911
Message ID:
01157307
Views:
38
Mark,
AFAIK anything you can do manually (plus some that you can't do manually -or just me-) within excel are doable via automation.
A quick sample:
lcXLS = Sys(5)+Curdir()+'customer.xls'
Use customer
Copy To (lcXLS) Type Xl5
Use

* Line styles
#Define xlContinuous	1
#Define xlDash	-4115
#Define xlDashDot	4
#Define xlDashDotDot	5
#Define xlDot	-4118
#Define xlDouble	-4119
#Define xlSlantDashDot	13
#Define xlLineStyleNone	-4142

* Border index
#Define xlInsideHorizontal	12
#Define xlInsideVertical	11
#Define xlDiagonalDown	5
#Define xlDiagonalUp	6
#Define xlEdgeBottom	9
#Define xlEdgeLeft	7
#Define xlEdgeRight	10
#Define xlEdgeTop	8

* Weight
#Define xlHairline	1
#Define xlMedium	-4138
#Define xlThick	4
#Define xlThin	2

oExcel = Createobject('Excel.Application')
With oExcel
  .Workbooks.Open(lcXLS)
  .Visible = .T.
  With .ActiveWorkbook.ActiveSheet.UsedRange
    With .Borders
      .LineStyle = xlDouble
      .ColorIndex = 5
    EndWith
    With .Borders(xlInsideVertical)
      .LineStyle = xlContinuous
      .Weight = xlThin
      .ColorIndex = 7
    Endwith
    With .Borders(xlInsideHorizontal)
      .LineStyle = xlContinuous
      .Weight = xlMedium
      .ColorIndex = 3
    ENDWITH
  * Font change on some range
	  .Rows(2).Font.Bold = .T.
	  .Columns(2).Font.Bold = .T.
	  .Cells(5,4).Font.Bold = .T.
  * cell color  
	  .Cells(2,3).Interior.Color = RGB(0,255,255)
  ENDWITH
Endwith
Cetin

>the excel sheets are done one at a time, they are invoices that the customer sends into a company, and they required this cell format in several individual cells but thay are in different colums and on different rows.
>I do have another query, is it possible to highlight a block of cells, say b1 and b2, c1 and c2 and then draw a border around them. I played about with it but it never worked for me and i'm not sure if this functionality is available through ole.
>~M
>
>>You're welcome.
>>If you're doing that in a loop, keep in mind it'd be slower. Instead you might get whole column/row/area references and do just one call. ie: To apply to only Column 2 ("B") in whole sheet used area:
>>
>>oleapp.activeworkbook.activesheet.UsedRange.Columns(2).NumberFormat = ...
>>
>>Cetin
>>
>>>tested, tried and trusted:) thanks Cetin, that was perfect.
>>>~M
>>>
>>>>Mark,
>>>>OleApp.cells.NumberFormat
>>>>
>>>>OleApp.cells means all cells.
>>>>
>>>>Instead of:
>>>>>
>>>>>OleApp.cells(lnCounter,3).Select   && selects the individual cell
>>>>>OleApp.cells.NumberFormat = "[$€-2] #,##0.00"   && change the format of cell
>>>>>
>>>>Try:
>>>>
>>>> OleApp.cells(lnCounter,3).NumberFormat = "[$€-2] #,##0.00"   && change the format of cell
>>>>
Cetin
>>>>
>>SNIP...
Ç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
Reply
Map
View

Click here to load this message in the networking platform