FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Open an excel file
Posts: 49
Joined: Thu Dec 22, 2005 12:50 PM
Open an excel file
Posted: Thu Mar 31, 2011 07:09 PM

I wonder if someone has a routine to open the excel file and play all the cells in a TXT or DBF.

Thanks

Kleyton

Fwh906

Brazil
Posts: 49
Joined: Thu Dec 22, 2005 12:50 PM
Re: Open an excel file
Posted: Thu Mar 31, 2011 08:18 PM

Able to read the excel cells, as shown below. Now how do you know if I got to the end of the file, or get a pallet of rows of xls file?

cArq := "D:\ImportDados\teste.xls"
TRY
oExcel:= GetActiveObject( "Excel.Application" )
CATCH
TRY
oExcel:= CreateObject( "Excel.Application" )
CATCH
MsgInfo("Excel is not installed in this PC. Unable to continue")
Return .F.
END
END

oBook = oExcel:Workbooks:Open(_cArq_)

oFolha := oBook:Get( "ActiveSheet")

? oFolha:Cells(14, 30):Value 
? oFolha:Cells(14, 31):Value 
? oFolha:Cells(14, 32):Value 
? oFolha:Cells(14, 33):Value 
? oFolha:Cells(14, 34):Value 
? oFolha:Cells(14, 35):Value

oExcel:Visible(.T.)
Kleyton

Fwh906

Brazil
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Open an excel file
Posted: Fri Apr 01, 2011 04:57 AM
Now how do you know if I got to the end of the file


If you are trying to retrieve data from the used rows of excel, then you can use the following commands. There are many ways and this is one among them.
Code (fw): Select all Collapse
// Retrieves the Used Rows and Column count
nTotRowCount  := oSheet:UsedRange:Rows:Count()
nTotColCount  := oSheet:UsedRange:Columns:Count()
MsgInfo("Used Rows :"+Str(nTotRowCount)+CRLF+"Used Cols :"+Str(nTotColCount))

//You can use nTotRowCount to process further. For eg.

nCurRow :=1
Do while nCurRow <= nTotRowCount
    ? oSheet:Cells(nCurRow,1):Value
    nCurRow ++
Enddo


Code (fw): Select all Collapse
// Method 2
nRow:=2 
Do while !empty(oExcel:Cells(nRow, 1):Value)
   nRow++
Enddo


Regards
Anser

Continue the discussion