Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Plug Existing Excel Cell with Table info
Message
From
22/07/2002 02:41:26
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00680666
Message ID:
00681018
Views:
19
>How can I write code that will place field values in specific excel-sheet locations ?
>
>The existing Excel spreadsheet must be used.
>
>Follow up question...
>What's the code to read values from specific sheet cells?
>
>TIA
>
>Edgar
Hi,

You need to create an Excel object, open the existing Excel file and have an object reference to the newly added worksheet in which you want to write the values.

The sample code is as given below :-

m.ExcelObject = CREATEOBJECT( "excel.application" )
if TYPE( 'm.ExcelObject' ) != "O" && in case, Excel is not loaded
return .f.
endif
*XLFileToBeOpened is the XL file you want to open
m.ExcelWorkBook = m.ExcelObject.WorkBooks.Open( m.XLFileToBeOpened )
*Add a new sheet after getting the existing sheet count
m.LastSheet =ExcelWorkBook.WorkSheets(ExcelWorkBook.WorkSheets.count)
m.ExcelWorkBook.WorkSheets.Add(,LastSheet)
*Now write the Table Headers for file OutDbf, replace OutDbf with your filename

use OutDbf
go top
with m.excelworkbook.activesheet
for m.i = 1 to Fcount( 'OutDbf' )
.rows(1).cells( m.i ).value = FIELD( m.i )
.rows(1).cells( m.i ).font.bold = .t.
endfor
*Now write data from the table onto the next rows
do while !eof()
m.i = m.i + 1
with .rows( m.i + 1 )
for m.j = 1 to FCOUNT( 'OutDbf' )
.cells( m.j ).value = EVAL( FIELD( m.j) )
endfor
endwith
skip
enddo
endwith

To get the value of a cell, use code like
m.CellValue = m.excelworkbook.activesheet.Cells( m.Row, m.Column).value

I had indented the code with spaces, but the spaces didn't come in the sent message. But I hope that it still helps.
Hitendra
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform