Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing arrays to Excel variant properties
Message
From
01/04/2004 08:40:56
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/04/2004 07:34:53
Norbert Kustra
SunSoft plus spol. s r.o.
Dolny Kubin, Slovakia
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00887487
Message ID:
00891452
Views:
33
>If your e-mail doesn't work, you can try this:
>Download the sample data from http://www.sunsoft.sk/ftp/test.zip
>Open TEST1.XLS - there are two pivottables on the sheet connected to the same pivotcache. Open VFP and try this code:
>xl=GETOBJECT(,"Excel.Application")
>pc=xl.ActiveWorkbook.PivotCaches(1)
>pc.CommandText = 'select * from DS1 ds1'
>... and I get error OLE error code 0x800a03ec: Unknown COM status code... :-(
>When I open TEST2 with one pivottable, all works fine.
>
>Do you have any idea how to reslove this problem?
>Thanks
> Norbert

Oh I forgot to post sample with one cache 2 pivots (one is in sheet2) and 2 selects. Here it is :
TEXT to m.lcSQL noshow
Select c.cust_id, c.company, ;
  o.order_id, o.order_date, ;
  e.First_Name-(' '+e.Last_Name) As Employee, ;
  oi.line_no, p.prod_name,;
  oi.unit_price, oi.quantity;
  FROM  testdata!customer c ;
  INNER Join testdata!orders o;
  ON  c.cust_id = o.cust_id ;
  INNER Join testdata!Employee e ;
  ON  o.emp_id = e.emp_id ;
  INNER Join testdata!orditems oi;
  ON  o.order_id = oi.order_id ;
  INNER Join testdata!products p ;
  ON  oi.product_id = p.product_id ;
  order By p.prod_name
ENDTEXT
m.lcSQL1 = Chrtran(m.lcSQL,';'+Chr(13)+Chr(10),'')+;
  ' where c.cust_id < "C"'
m.lcSQL2 = Chrtran(m.lcSQL,';'+Chr(13)+Chr(10),'')+;
  ' where c.cust_id >= "C"'


lcConnPath = Sys(5)+Curdir()

Alines(laRowFields,'prod_name')
Alines(laColumnFields,'Employee')
Alines(laPageFields,'cust_id')

#include xlConstants.h
oExcel = Createobject('Excel.Application')
With oExcel
  .Workbooks.Add
  With .ActiveWorkbook
    oRange1 = .ActiveSheet.Range('A3')
    oRange2 = .WorkSheets('Sheet2').Range('A3')

    With .PivotCaches.Add(xlExternal)
      .Connection  = "OLEDB;Provider=VFPOLEDB;Data Source="+m.lcConnPath
      .CommandType = xlCmdSQL
      .CommandText = m.lcSQL1
      .CreatePivotTable(m.oRange1, "myPivTable")
      .CreatePivotTable(m.oRange2, "myPivTable2")
    Endwith
    With .ActiveSheet.PivotTables("myPivTable")
      .AddFields(@laRowFields, @laColumnFields, @laPageFields)
      .PivotFields('Quantity').Orientation = xlDataField
    Endwith

    Alines(laRowFields,'cust_id')
    Alines(laColumnFields,'Employee')

    With .WorkSheets('Sheet2').PivotTables("myPivTable2")
      .AddFields(@laRowFields, @laColumnFields)
      .PivotFields('Quantity').Orientation = xlDataField
    Endwith
  Endwith
  .Visible = .T.
  Wait Window Timeout 10
  ?? Chr(7)+Chr(7)
  With .ActiveWorkbook.PivotCaches(1)
    .CommandText = m.lcSQL2
    .Refresh
  Endwith
Endwith
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