发信人: luhan()
整理人: leitiger(2002-06-11 11:22:18), 站内信件
|
long numcols , numrows , c, r
OLEObject xlapp , xlsub
int ret
// Set the # of columns and rows to process
// Currently Set to copy the entire DW
numcols = long(dw_1.Object.DataWindow.Column.Count)
numrows = dw_1.RowCount()
// Create the oleobject variable xlapp
xlApp = Create OLEObject
// Connect to Excel and check the return code
ret = xlApp.ConnectToNewObject( "Excel.Sheet" )
if ret < 0 then
MessageBox("Connect to Excel Failed !",string(ret))
return
end if
// Open a particular Excel file
xlApp.Application.Workbooks.Open("c:\file1.xls") //,false,true
// Make Excel visible
xlApp.Application.Visible = true
// Resolve the Excel reference once
// This technique shortens the script and improves performance
xlsub = xlapp.Application.ActiveWorkbook.Worksheets[1]
// Loop thru the Datawindow and Excel sheet
// The for/next loop copies all rows for each column
For c = 1 to numcols
For r = 1 to numrows
xlsub.cells[r,c] = dw_1.object.data[r,c]
Next
Next
// Save opened file
//xlApp.Application.Activeworkbook.Save()
// SaveAs a different filename
//xlApp.Application.Activeworkbook.SaveAs("c:\file2.xls")
// clean up
xlApp.DisConnectObject()
Destroy xlapp
-- ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.101.160.46]
|
|