打开工作簿,对xls文件设置密码保护后,退出时提示: 是否保存修改?如果不让这个提示弹出来?ObjExcel.ActiveWorkbook.Password = '123123'
ObjExcel.Quit() 如果我在quit前用save的话,又会提示:是否替换已经存在的文件?我该如何做呢?
ObjExcel.Quit() 如果我在quit前用save的话,又会提示:是否替换已经存在的文件?我该如何做呢?
调试欢乐多
先将原文件移到其他目录,操作完成,saveas目标文件:
int i,li_ret
long ll_cell
int li_colcount
string ls_pathname
//string ls_filenameint li_rowint li_rowCount
string ls_data
long ll_currow
long ll_cellrow
string ls_tmpfilels_pathname = as_path //ProfileString ("smp.ini", "filepath", "input1","")li_colcount = integer(idw_dw.object.datawindow.column.count) //ai_colcount //25 // dw列数if li_colcount < 1 then return ls_tmpfile = gs_app_path+"\tmp.sys"
if FileExists(ls_tmpfile) then
if filedelete(ls_tmpfile) then
f_write_filelog("3","删除临时文件:" +ls_tmpfile+ "失败")
return
end if
end if
if filemove(ls_pathname,ls_tmpfile) < 1 then return OLEObject excelole
excelole = CREATE OLEObjectli_ret = excelole.ConnectToNewObject("Excel.Application")
if li_ret <> 0 then
MessageBox('Excel error','Excel cannot connect,error number:' + string(li_ret))
excelole.disconnectobject()
DESTROY excelole
return
end ifsetpointer(Hourglass!)excelole.visible = 0 excelole.Workbooks.Open(ls_tmpfile,3, false, 1, '123123','123123') //打开密码保护的文件
excelole.Worksheets[1].activate //li_rowCount=excelole.Application.ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count
li_rowCount = idw_dw.rowcount()
for li_row = 1 to li_rowCount
ll_cellrow = al_filerowcount + li_row
for i = 1 to li_colcount
ls_data = string(idw_dw.object.data[li_row,i]) //= adw_data.Describe(ls_colname[i] +'_t' + '.text')
excelole.cells(ll_cellrow,i).value = ls_data
next
next
excelole.ActiveWorkbook.Saveas(ls_pathname)
excelole.Workbooks.close
excelole.application.quit()
excelole.disconnectobject()
DESTROY excelole setpointer(Arrow!)
FileDelete(ls_tmpfile)
return