Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Plug Existing Excel Cell with Table info
Message
De
22/07/2002 02:41:26
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00680666
Message ID:
00681018
Vues:
18
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform