long ll_rownum
string ls_dotname,ls_docname,ls_value
integer i,k,j,li_Row//,li_mod,li_div
//Word Ole对象
OLEObject ole_word
ll_rownum = dw_print.RowCount()
if ll_rownum = 0 then return false
ole_word = CREATE OLEObject
//连接word
IF ole_word.ConnectToNewObject("word.Application") <> 0 THEN
Destroy ole_word
MessageBox('OLE错误','OLE无法连接!')
return false
END IF
ls_dotname = gs_current_dir + "\template\label_" + string(ai_format) + ".dot"
if Not FileExists(ls_dotname) then
Destroy ole_word
MessageBox("提示","Word模板文件不存在。")
return false
End if
//ole_word.Visible = true
hpb_1.visible = true
hpb_1.Position = 0
hpb_1.SetRange(0,ll_rownum)
choose case ai_format
case 1
li_Row = 15
case 2
li_Row = 7
case 3
li_Row = 4
end choose
for i = 1 to ll_rownum
hpb_1.StepIt()
K++
if Mod(i,li_Row) = 1 then
//按照模板新建word文件
ole_word.Documents.Add(ls_dotname)
k = 1
End if
Try
ls_value = dw_print.getitemstring(i,'item237')
if isnull(ls_value) then ls_value='';
ole_word.selection.goto(true,0,0,'item237_' + string(k,"00"))
ole_word.selection.typetext(ls_value)
//档案分类号
ls_value = dw_print.getitemstring(i,'vol_dh')
if isnull(ls_value) then ls_value='';
ole_word.selection.goto(true,0,0,'vol_dh_' + string(k,"00"))
ole_word.selection.typetext(ls_value)
//文档主标题
ls_value = dw_print.getitemstring(i,'title')
if isnull(ls_value) then ls_value='';
ole_word.selection.goto(true,0,0,'title_' + string(k,"00"))
ole_word.selection.typetext(ls_value)
Catch (RuntimeError ErrMark)
MessageBox("提示","Word模板已经损坏。~r~n详细信息为:~r~n" + ErrMark.GetMessage() + &
"~r~n请与系统管理员联系。")
Exit
End Try
If K = li_Row Or i = ll_rownum then
//打印
Try
ole_word.application.ActiveDocument.printout()
ole_word.ActiveDocument.Close(False)
Catch (RuntimeError ErrPrint)
MessageBox("提示","找不到打印机。~r~n详细信息为:~r~n" + ErrPrint.GetMessage() + &
"~r~n请与系统管理员联系。")
Exit
end try
End if
Next