Home > database >  PB call EXCEL error control (urgent)
PB call EXCEL error control (urgent)

Time:09-26

Use an excel template, for each unit of life into a excel file, and personnel information into the new generated file, the file named after the serial number of every worker,
In a loop variable (seemingly random, the more the greater the chances of) there is an error, lines of code statements for ole_object. Workbooks. Open (ls_new_docname)//open the target file, error for the name not found accessing external object property workbooks
Specific example code is as follows:
//first production all files
An integer value
String docname, named ls_pathname
String ls_new_docname, ls_new_named
Value=https://bbs.csdn.net/topics/GetFileSaveName (" select file name ", docname, named, "like", "EXCEL file (*. XLS), *. XLS")//to save the file name and path
If the value & lt;> 1 then return
Ls_pathname=left (docname, pos (docname, named) - 1)

Ll_rowcount=dw_7. RowCount ()
For ll_i=1 to ll_rowcount
Ls_pnumber=dw_7. Getitemstring (ll_i, 'aa_u_personal_p_number)
Ls_new_named=ls_pnumber + 'personal stamp. XLS'
Ls_new_docname=ls_pathname + ls_new_named
I=CopyFileA (gs_current_path + "\ XLS \ personal stamp sample tables. XLS", ls_new_named, 0)
//copy the template files to save the file
If I & lt;> 1 then
MessageBox (' message ', 'save the mistake, please check! '+ gs_current_path + "\ XLS \ personal stamp sample table. XLS")
Return
End the if
Next

//cycle again, open each file, fill in the content, the first two loops is together, separate the wrong before, but didn't solve practical problems
OLEObject ole_object
For ll_i=1 to ll_rowcount
Ls_pnumber=dw_7. Getitemstring (ll_i, 'aa_u_personal_p_number)
Ls_new_named=ls_pnumber + 'personal stamp. XLS'
Ls_new_docname=ls_pathname + ls_new_named
//this is in error, I added, using PB open the file test
The do while TRUE
If FileExists (ls_new_docname) then
Li_FileNum=FileOpen (ls_new_docname StreamMode! , Read! , LockRead!)
If li_FileNum & lt;> 1 then//open the success
If FileClose (li_FileNum)=1 then st_5. Text='close success'
The exit
The else
St_5. Text='open unsuccessful'
End the if
End the if
Loop
//can through the above this file exists, and can open, but still random errors when using ole opened
SetFileAttributes (ls_new_docname, 32)//set the saved file to write
Ole_object=CREATE OLEObject
Int li_ret
Li_ret=ole_object. ConnectToObject (" ", "Excel. Application")
If li_ret & lt;> 0 then
Li_ret=ole_object. ConnectToNewObject (" Excel. Application ")
If li_ret & lt;> 0 then
Ole_object. DisconnectObject disconnected ()//
Destroy ole_object//destruction of EXCEL service object
MessageBox (' OLE errors', 'OLE unable to connect! Error number: "+ string (li_ret))
Return
End the if
Ole_object. Application. The Visible=false
End the if

Ole_object. Workbooks. Open (ls_new_docname)//open the target file, the random error, when circulating big, appear likely
Ole_object. Workbooks (ls_new_named). Activate ()
Ls_pname=dw_7. Getitemstring (ll_i, 'aa_u_personal_p_name)
Ole_object. Worksheets (1) cells (3, 2). The value=https://bbs.csdn.net/topics/ls_pname
Ole_object. Application. The Quit ()
Ole_object. DisconnectObject disconnected ()//
Destroy ole_object//destruction of EXCEL service object
//yield ()
Next

Ask ace to give directions, I tried a afternoon, include hard disk write cache off, such as, ah, thank you!

CodePudding user response:

Try to debug and under different OS XP small probability of error, VISTA and Windows 7 probability under the big, related to system where? How can foresee whether to take the wrong, and then solve?
Now add a loop variable specified schedule temporarily, when there is an error, again from the wrong place to continue, this method is too weak,,,
Ole_object. Workbooks. Open (ls_new_docname) directly out of the system level error, phase internal cover can't ah,,,
How to do?
How to implement such demand?
A points, masters come to meet you

CodePudding user response:

Don't have to determine whether a file exists and can open, through
If not ole_object. Workbooks. Open (ls_new_docname) then
//can't open the
end if

CodePudding user response:

Try
Ole_object. Workbooks. Open (ls_new_docname)
.
The Catch (runtimeerror runx)
//if the error
End the Try

CodePudding user response:

Lzcc123: problem solved? How to solve of,

CodePudding user response:

When lole_xlsFile. Workbooks. Open (" c: \ ABC. XLS ") can't use
Use the lole_xlsFile. Application. Workbooks. Open (" c: \ ABC. XLS ")
  • Related