Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding out programmatically how many rows in excel.
Message
From
28/01/2003 03:52:10
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00745897
Message ID:
00746116
Views:
18
>I am programmatically saving an excel file to dbf format. I do not know how many rows will be in the spreadsheet does anyone know how I can figure this out?
>
>Thanks

Julie,
Along the lines of this thread I now see what you meant in your other post. In your code comment the line that selects A1:T1 range. By selecting headers you're telling excel you only want that portion (which is structure).
with oExcel.ActiveWorkbook
 .ActiveSheet.Range('A1:T30').Select
 .SaveAs(lcFileName,8)
endwith

* Saves only 29 rows - 1 header + 29 rows

with oExcel.ActiveWorkbook
* .ActiveSheet.Range('A1:T30').Select && and no selection
 .SaveAs(lcFileName,8)
endwith
*Saves all data. The start-end row/column doesn't matter, excel finds it
However if you really have to find out rowcount, colcount, address etc here are some usefull ones :

* All used part in sheet
oExcel.Activeworkbook.ActiveSheet.UsedRange

*Last cell used in sheet
oExcel.Activeworkbook.ActiveSheet.Range("A1").SpecialCells(xlLastCell)

*Nonempty cells around a given range - island
oExcel.Activeworkbook.ActiveSheet.Range("A1").CurrentRegion

All of the above return a range object and you can use any functions, properties that applies to range object. ie:
#define xlA1  1
#define xlLastCell  11

with oExcel.Activeworkbook.ActiveSheet
  lcLastCell = .Range("A1").SpecialCells(xlLastCell).Address(.f.,.f.,xlA1)
  ? 'Last Cell',lcLastCell
  with .UsedRange
     ? 'Address',.Address(.f.,.f.,xlA1)
     ? 'Rows',.Rows.Count, 'Cols', .Columns.Count
  endwith
  .Range("A1").SpecialCells(xlLastCell).CurrentRegion.Select
endwith
PS: UsedRange doesn't mean a range starting from 'A1'. If say you only had data in M5:U90 it means that part. Without a selection is made SaveAs defaults to this range and for that reason even if your data was in M5:U90 it's saved properly.
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
Reply
Map
View

Click here to load this message in the networking platform