那有点麻烦了 上述word模板套打 按照老师之前指导的加入毫秒 以及加入try 都没有能够正确避免弹出文件存在 然后需要另存为的提示!
一旦弹出另存为提示 然后页面就卡起了,因为后端必须要取消另存为保存才能让客户端继续使用,不然就一直卡起
因word模板太多,也不便于一个个的全部按照专业报表去设计!
前端代码:
({
button6: {
text: '{{text}}',
//系统自动匹配标题
visible: true,
click: function() { //按钮单击事件
$.post("form385_getdata2.Ajax", {},
function(res) {
res = JSON.parse(res); //把后端传来的字符串转json对象
if (res.空号文书值 == '是') {
$.post("form385_word.Ajax", {
guid: e.form.guid,
创建人: e.form.user.name,
文书名:"谈话通知书",
},
function(res) {
var a = document.createElement("a");
a.setAttribute("href", myurl + res);
a.setAttribute("target", "打印文书");
document.body.appendChild(a);
a.click();
a.remove();
})
} else {
if (e.form.文号.value == '') {
e.form.alert("当前禁止打印没有生成文号的文书,请联系管理员审核!", "温馨提示");
} else {
$.post("form385_word.Ajax", {
guid: e.form.guid,
创建人: e.form.user.name,
文书名:"谈话通知书",
},
function(res) {
var a = document.createElement("a");
a.setAttribute("href", myurl + res);
a.setAttribute("target", "打印文书");
document.body.appendChild(a);
a.click();
a.remove();
})
}
}
})
}
}
})
后端代码:
Public Sub form385_word_Ajax(rq as Request) 'form202_excel_Ajax与前端函数对应,注意_Ajax和 .Ajax区别
Dim e As RequestEventArgs = rq.e
Dim cmd As SQLCommand = rq.cmd
Dim tm As String = ProjectPath & "Attachments\" & e.Values("文书名") & ".doc" '指定模板文件
If FileSys.FileExists(tm) Then
Try
Dim time As String = Format(Date.now, "yyyyMMddHHmmssfffff")
Dim f1 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.doc" '指定目标文件
Dim f2 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.pdf" '指定目标PDF文件
Dim wrt As New WordReport(tm, f1)
wrt.AddDataTable(e.Values("文书名"), "主数据源", "Se lect * from {" & e.Values("文书名") & "} where guid = '" & e.Values("guid") & "' ")
cmd.CommandText = "sel ect * from SYS_Dictionary where 字典值='是' and 分类='PDF预览'"
Dim dt As DataTable = cmd.ExecuteReader()
If dt.DataRows.Count > 0 Then
wrt.Build()
wrt.SaveToPDF(f2) '保存为PDF文件
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.pdf")
Else
wrt.Build()
'wrt.Show()
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.doc")
End If
Catch ex As Exception
Dim time As String = Format(Date.now, "yyyyMMddHHmmssfffff")
Dim f1 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.doc" '指定目标文件
Dim f2 As String = ProjectPath & "mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.pdf" '指定目标PDF文件
Dim wrt As New WordReport(tm, f1)
wrt.AddDataTable(e.Values("文书名"), "主数据源", "Se lect * from {" & e.Values("文书名") & "} where guid = '" & e.Values("guid") & "' ")
cmd.CommandText = "sele ct * from SYS_Dictionary where 字典值='是' and 分类='PDF预览'"
Dim dt As DataTable = cmd.ExecuteReader()
If dt.DataRows.Count > 0 Then
wrt.Build()
wrt.SaveToPDF(f2) '保存为PDF文件
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.pdf")
Else
wrt.Build()
'wrt.Show()
wrt.Quit() '退出
e.WriteString("\mybaobiao\" & e.Values("文书名") & e.Values("创建人") & e.Values("guid") & time & "存根联.doc")
End If
End Try
Else
e.WriteString(e.Values("文书名") & "存根联[文件不存在或已经被删除!]")
End If
End Sub
[此贴子已经被作者于2022/9/1 11:46:36编辑过]