在PB中实现对EXCEL的操作
在PB实现象下面的VFP 的应用,好将资料放到一个电子表格
Myexcel=createobject('EXCEL.APPLICATION')
MYEXCEL.VISIBLE=.f.
MYEXCEL.WORKBOOKS.ADD
O1=MYEXCEL.ACTIVEWORKBOOK.SHEETS(1)
O1.NAME='IN'
o1.CELLS(1,2).VALUE='abc'
又如:
excel=createobject('excel.application')
EXCEL.VISIBLE=.T.
ExcelFile="D:\MYDOCU~1\DC1999\DC_MDT.XLS"
if not file(ExcelFile)
wait wind 'no file:'+excelfile
return
endif
excel.workbooks.open(ExcelFile)
PB实现象上述VFP 的应用,代码如下:
方法一:
OLEObject ExcelServer
integer ExcelOK
ExcelServer = CREATE OLEObject
ExcelOK = ExcelServer.ConnectToNewObject( "excel.application" )
ExcelServer.Workbooks.Open("c:\book.xls")
ExcelServer.ActiveWorkBook.Sheets("Sheet2").Select
ExcelServer.ActiveSheet.Cells(1,1).value = "书名"
ExcelServer.Application.Visible = TRUE
方法二:
先启动excel文件
long handle_1
handle_1 = OpenChannel("Excel", "c:\book.xls")
//建立与EXCEL的通道
setremote("r1c1","书号","excel"," c:\book.xls")
setremote("r1c2","书名","excel"," c:\book.xls")
//更改某一行或某一列的值,同时关闭通道
closechannel(handle_1,handle(parent))