PB中如何实现对EXCEL的操作?
问:本人以曾是用VFP 编程的,曾编过VFP&EXCLE的应用如:
Myexcel=createobject('EXCEL.APPLICATION')
MYEXCEL.VISIBLE=.f.
MYEXCEL.WORKBOOKS.ADD
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))