天天看点

PB打开EXCEL文件报错

OLEObject ExcelServer

Integer ExcelOk

string ls_pathname

ls_pathname = "e:\gzdr\book1.xlsx"

IF FileExists(ls_pathname)=FALSE then

MessageBox("msg","File is not found")

return

end if

ExcelServer = CREATE OLEObject

ExcelOK = ExcelServer.ConnectToNewObject("excel.application")   

ExcelServer.Workbooks.Open(ls_pathname)   

//ExcelServer.ActiveWorkBook.Sheets("Sheet1").Select   

//ExcelServer.Application.Visible   =   TRUE     

//ExcelServer.ActiveWorkBook.Close()

ExcelServer.Quit

每次都是第8行报错

ExcelServer.Workbooks.Open(ls_pathname)   

,但实际上是打开文件的

PB打开EXCEL文件报错

后来发现,需要让EXCEL应用显示出来,就不会报错了,也不知道为啥原因,所以只有显示后马上最小化

ExcelServer.Visible = TRUE

ExcelServer.WindowState = -4140  //最小化