Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Automation of Excel under IE
Message
From
05/11/2004 11:42:26
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
05/11/2004 11:36:01
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00958541
Message ID:
00958546
Views:
35
>My client uses a web site to get some data. When the user asks for the data to be downloaded, a 2nd instance of IE starts with Excel running in it (among other things the Excel menus are different, the menus do not work with the Alt key from the keyboard, etc.). The XLS is sitting on the the web site. Manually the user can save it to the hard drive. If I bring up VFP and put
>
>
>oExcel = GetObject(, "Excel.Application")
>WAIT WINDOW oExcel.Range ("A1").value
>
>
>in the Command Window, everything is fine. When I try,
>
>
>oExcel = GetObject(, "Excel.Application")
>oWB=oExcel.ActiveWorkbook
>oWB.SaveAs ("C:\zz")
>
>
>I get messages about oWB not being an object. If I bring up Excel the "normal" way, put some data in it, the 3 lines above work just fine.
>
>Can someone explain what is happening? Can I use Automation in VFP here?
>
>Thanks.
>
>
>Tim

Tim,
There might not be an activeworkbook.
Here is a sample (it might be OWC.SpreadSheet):
lcXLSFile = Sys(5)+Curdir()+'myCustomer.xls'
Use customer
Copy To (m.lcXLSFile) Type Xls
Use


oForm = Createobject('form1',m.lcXLSFile)
oForm.Show()
Read Events

Define Class form1 As Form
  Top = 0
  Left = 0
  Height = 470
  Width = 740
  DoCreate = .T.
  Caption = "HTML sample"
  Name = "Form1"

  * This is IE control - you'd use webbrowser4 from gallery instead
  * just because it already has some checks, extra pem. ie: wouldn't need readystate part
  * for the sake of keeping code short here I directly use olecontrol itself
  Add Object htmlviewer As OleControl With ;
    Top = 12, ;
    Left = 12, ;
    Height = 396, ;
    Width = 708, ;
    Visible = .T., ;
    Name = "HTMLViewer", ;
    OleClass = 'Shell.Explorer'

  Add Object cmdExcel As CommandButton With ;
    Height = 25, ;
    Left = 12, ;
    Top = 432, ;
    Width = 60

  Procedure Init
  Lparameters tcXLSFile
  With Thisform.htmlviewer
    .Navigate2('file://'+m.tcXLSFile)
    Do While .ReadyState # 4 && Wait for ready state
    Enddo
  Endwith
Endproc

  Procedure cmdExcel.Click
  oXLS = Thisform.htmlviewer.Object.Document
  oExcel = oXLS.Application
  oExcel.CommandBars("Standard").Visible = .T.
  oExcel.CommandBars("Formatting").Visible = .T.
  lcRange = Trim(Thisform._GetChar(2))+'1:'+;
    Trim(Thisform._GetChar(5)+'9')
  *  oExcel.ActiveWorkbook.ActiveSheet.Range(m.lcRange).Interior.ColorIndex = 3
  With oExcel.ActiveWorkbook.ActiveSheet.UsedRange
    With .Rows(1)
      For ix=1 to .Columns.Count
      	.Cells(1,m.ix).Value = Upper(.Cells(1,m.ix).Value)
      endfor
      .Interior.ColorIndex = 3
      .Font.Color = Rgb(255,255,255)
    Endwith
    .Columns.Autofit
  Endwith
Endproc

  Procedure QueryUnload
  Clear Events
Endproc

  Procedure _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 This._GetChar(Int(Iif(tnColumn % 26 = 0,tnColumn - 1, tnColumn) / 26)) + ;
      this._GetChar((tnColumn-1)%26+1)
  Endif

Endproc
Enddefine
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