Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel active rows
Message
De
23/05/2003 05:34:58
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00792018
Message ID:
00792110
Vues:
23
This message has been marked as the solution to the initial question of the thread.
>Sorry folks, I might have put you wrong there. It appears that
>
>
>oExcel = CREATEOBJECT([Excel.Application])
>WITH oExcel
>    .Workbooks.Open(GETFILE())
>    ?.Worksheets("Sheet1").UsedRange.Rows.Count
>* or
>    ?.ActiveSheet.UsedRange.Rows.Count
>    .Workbooks.Close()
>ENDWITH
>oExcel=.F.
>
>Returns the number of rows used in the sheet.
>
>Regards
>Geoff
Snip...

Geoff,
At first look UsedRange.Rows.Count is the answer but it's NOT.
UsedRange returns info about 'Used' cells in a sheet. If your sheet has some columns and/or rows left empty at start then what you get is not what you should get to find first available unused row. Suppose someone has customer.xls generated from customer table but user moved the data to start at say M80 and saved. If customer.dbf had 92 rows and 10 columns, UsedRange.Rows.Count and USedRange.Columns.Count would still return 92 and 10 not 80+92, M+10. Hard to describe :) To see what I mean create a test customer.xls, open manually and move the data to start from another row/col instead of A1, save, quit and run (assuming saved in current folder) :
#Define xlA1  1
#Define xlLastCell  11

lcXLS = Sys(5)+Curdir()+'customer.xls'
oExcel = Createobject('Excel.application')
oExcel.Workbooks.Open(lcXLS)
With oExcel.Activeworkbook.ActiveSheet
  lcLastCell = .Range("A1").SpecialCells(xlLastCell).Address(.F.,.F.,xlA1)
  ? 'Last Cell',lcLastCell
  With .UsedRange
    ? 'Used Range Address',.Address(.F.,.F.,xlA1)
    ? 'Used Range Rows',.Rows.Count, 'Cols', .Columns.Count
  Endwith
  lcFirstUnusedRowCol = "A"+;
     Transform(Int(Val(Chrtran(;
       lcLastCell,Chrtran(lcLastCell,'0123456789',''),''))+1))
  ? 'First Column at First unused row',lcFirstUnusedRowCol
  .Range(lcFirstUnusedRowCol).Activate
Endwith
oExcel.Visible = .T.
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