Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel Range.OffSet problem
Message
De
25/04/2003 09:01:52
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00781404
Message ID:
00781426
Vues:
18
>Hello All,
>I'm trying out an Excel example from the book "Microsoft Office Automation with Visual Foxpro" , the example in question "Scans" a table, populates a couple of columns and moves down a row ( in the worksheet ) using the Range.Offset method, however when I look at the output spreadsheet there is only one row populated which contains data from the last record, indicating the Offset method is not working, any ideas as to why this is?
>
>my code snippet
>I've left all the object creation code out for brevity
>
>
>oRange = .Range("A12:C12")
>
>scan
>    .Columns[1].Value = myfieldata1
>    .Columns[2].Value = myfieldata2
>    .Columns[3].Value = myfieldata3
>    oRange = oRange.Offset(1,0)
>endscan
>
>
>
>The fist iteration is fine but subsequent ones are overwriting the previous values, I'm using VFP 7.0. and Office 97 on Win XP pro, any help much appreciated
>
>regards
>
>Pete Kane

Pete,
I think you cut more than needed for brevity :) I bet your code is similar to :
oRange = .Range("A12:C12")

with oRange
scan
    .Columns[1].Value = myfieldata1
    .Columns[2].Value = myfieldata2
    .Columns[3].Value = myfieldata3
    oRange = oRange.Offset(1,0)
endscan
endwith
Or worse with has a higher level object.
If that's the case remember oRange setting in loop has no effect. With would grab the first reference and repeatedly values in them would be changed in scan..endscan leaving you with the last record.
Prefix the .Columns with oRange. ie:
Use Data\customer
oExcel = Createobject('Excel.Application')
With oExcel
  .Workbooks.Add
  .Visible = .T.
  With .ActiveWorkbook.ActiveSheet
    oRange = .Range("A12:C12")
    Scan
      oRange.Columns[1].Value = cust_id
      oRange.Columns[2].Value = company
      oRange.Columns[3].Value = Title
      oRange = oRange.Offset(1,0)
    Endscan
  Endwith
Endwith
PS: I think this is only for sampling Range.Offsett, otherwise setting cell by cell in excel is slow.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform