-- 作者:ayiken
-- 发布时间:2016/1/17 10:52:00
-- word报表
Dim tm As String = ProjectPath & "Attachments\\查房记录.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\查房记录.doc" \'指定目标文件 Dim wrt As New WordReport(Tables("住院记录"),tm,fl) \'定义一个WordReport For i As Integer = Tables("住院记录").TopPosition To Tables("住院记录").BottomPosition Dim r As Row = Tables("住院记录").Rows(i) Dim str As String = "" Dim drs As List(Of DataRow) = DataTables("上级医师查房记录").Select("住院号 = \'" & r("病人信息_住院号") & "\'", "记录日期") For j As Integer = 1 To 10 If j <= drs.Count Then Dim cdr As DataRow = drs(j-1) wrt.ReplaceOne("[记录日期" & j & "]", cdr("记录日期") & chr(13) ) wrt.ReplaceOne("[住院号" & j & "]", cdr("住院号") & chr(0) ) wrt.ReplaceOne("[床号" & j & "]", cdr("床号") & chr(13) ) wrt.ReplaceOne("[姓名" & j & "]", cdr("姓名") & chr(0)) wrt.ReplaceOne("[主症" & j & "]", cdr("病史_主症") & chr(0)) wrt.ReplaceOne("[现病史" & j & "]", cdr("病史_现病史") & chr(0)) wrt.ReplaceOne("[既往史" & j & "]", cdr("病史_既往史") & chr(0)) wrt.ReplaceOne("[体温" & j & "]", cdr("体格检查_体温T") & chr(0)) wrt.ReplaceOne("[血压" & j & "]", cdr("体格检查_血压BP") & chr(0)) wrt.ReplaceOne("[呼吸频率" & j & "]", cdr("体格检查_呼吸频率R") & chr(0)) wrt.ReplaceOne("[脉搏频率" & j & "]", cdr("体格检查_脉搏频率P") & chr(0)) wrt.ReplaceOne("[记录内容" & j & "]", cdr("记录内容") & chr(13)) wrt.ReplaceOne("[上级医师" & j & "]", cdr("上级医师") & chr(13)) wrt.ReplaceOne("[记录医师" & j & "]", cdr("记录医师") & chr(13)) wrt.ReplaceOne("[记录日期_提示" & j & "]", "记录日期:") wrt.ReplaceOne("[住院号_提示" & j & "]", "住院号:") wrt.ReplaceOne("[床号_提示" & j & "]", "床号:") wrt.ReplaceOne("[姓名_提示" & j & "]", "姓名:") wrt.ReplaceOne("[主症_提示" & j & "]", "病史_主症:") wrt.ReplaceOne("[现病史_提示" & j & "]", "病史_现病史:") wrt.ReplaceOne("[既往史_提示" & j & "]", "病史_既往史:") wrt.ReplaceOne("[体温_提示" & j & "]", "T:") wrt.ReplaceOne("[血压_提示" & j & "]", "BP:") wrt.ReplaceOne("[呼吸频率_提示" & j & "]", "R:") wrt.ReplaceOne("[脉搏频率_提示" & j & "]", "P:") wrt.ReplaceOne("[记录内容_提示" & j & "]", "记录内容:") wrt.ReplaceOne("[上级医师_提示" & j & "]", "上级医师:") wrt.ReplaceOne("[记录医师_提示" & j & "]", "记录医师:") wrt.ReplaceOne("[换行" & j & "]", chr(13) & chr(13)) Else wrt.ReplaceOne("[记录日期" & j & "]", "") wrt.ReplaceOne("[住院号" & j & "]", "") wrt.ReplaceOne("[床号" & j & "]", "") wrt.ReplaceOne("[姓名" & j & "]", "") wrt.ReplaceOne("[记录内容" & j & "]", "") wrt.ReplaceOne("[体温" & j & "]", "") wrt.ReplaceOne("[血压" & j & "]", "") wrt.ReplaceOne("[呼吸频率" & j & "]", "") wrt.ReplaceOne("[脉搏频率" & j & "]", "") wrt.ReplaceOne("[上级医师" & j & "]", "") wrt.ReplaceOne("[记录医师" & j & "]", "") wrt.ReplaceOne("[主症" & j & "]", "") wrt.ReplaceOne("[现病史" & j & "]", "") wrt.ReplaceOne("[既往史" & j & "]", "") wrt.ReplaceOne("[记录日期_提示" & j & "]", "") wrt.ReplaceOne("[住院号_提示" & j & "]", "") wrt.ReplaceOne("[床号_提示" & j & "]", "") wrt.ReplaceOne("[姓名_提示" & j & "]", "") wrt.ReplaceOne("[记录内容_提示" & j & "]", "") wrt.ReplaceOne("[体温_提示" & j & "]", "") wrt.ReplaceOne("[血压_提示" & j & "]", "") wrt.ReplaceOne("[呼吸频率_提示" & j & "]", "") wrt.ReplaceOne("[脉搏频率_提示" & j & "]", "") wrt.ReplaceOne("[上级医师_提示" & j & "]", "") wrt.ReplaceOne("[记录医师_提示" & j & "]", "") wrt.ReplaceOne("[主症_提示" & j & "]", "") wrt.ReplaceOne("[现病史_提示" & j & "]", "") wrt.ReplaceOne("[既往史_提示" & j & "]", "") wrt.ReplaceOne("[换行" & j & "]", "") End If Next wrt.BuildOne(r) \'逐行生成报表 Next wrt.quit Dim app As New MSWord.Application try Dim fileName = fl Dim doc = app.Documents.Open(fileName) doc.Protect (Password:="123456", NoReset:=False, Type:= _ MsWord.WdProtectionType.wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False) app.Documents.save app.Visible = True catch ex As exception msgbox(ex.message) app.Quit finally End try
上面代码中word保护密码那一块儿不要的话怎么改,我改的如下,打打不开word报表,也没报错,就是卡机
Dim tm As String = ProjectPath & "Attachments\\查房记录.doc" \'指定模板文件 Dim fl As String = ProjectPath & "Reports\\查房记录.doc" \'指定目标文件 Dim wrt As New WordReport(Tables("住院记录"),tm,fl) \'定义一个WordReport For i As Integer = Tables("住院记录").TopPosition To Tables("住院记录").BottomPosition Dim r As Row = Tables("住院记录").Rows(i) Dim str As String = "" Dim drs As List(Of DataRow) = DataTables("上级医师查房记录").Select("住院号 = \'" & r("病人信息_住院号") & "\'", "记录日期") For j As Integer = 1 To 10 If j <= drs.Count Then Dim cdr As DataRow = drs(j-1) wrt.ReplaceOne("[记录日期" & j & "]", cdr("记录日期") & chr(13) ) wrt.ReplaceOne("[住院号" & j & "]", cdr("住院号") & chr(0) ) wrt.ReplaceOne("[床号" & j & "]", cdr("床号") & chr(13) ) wrt.ReplaceOne("[姓名" & j & "]", cdr("姓名") & chr(0)) wrt.ReplaceOne("[主症" & j & "]", cdr("病史_主症") & chr(0)) wrt.ReplaceOne("[现病史" & j & "]", cdr("病史_现病史") & chr(0)) wrt.ReplaceOne("[既往史" & j & "]", cdr("病史_既往史") & chr(0)) wrt.ReplaceOne("[体温" & j & "]", cdr("体格检查_体温T") & chr(0)) wrt.ReplaceOne("[血压" & j & "]", cdr("体格检查_血压BP") & chr(0)) wrt.ReplaceOne("[呼吸频率" & j & "]", cdr("体格检查_呼吸频率R") & chr(0)) wrt.ReplaceOne("[脉搏频率" & j & "]", cdr("体格检查_脉搏频率P") & chr(0)) wrt.ReplaceOne("[记录内容" & j & "]", cdr("记录内容") & chr(13)) wrt.ReplaceOne("[上级医师" & j & "]", cdr("上级医师") & chr(13)) wrt.ReplaceOne("[记录医师" & j & "]", cdr("记录医师") & chr(13)) wrt.ReplaceOne("[记录日期_提示" & j & "]", "记录日期:") wrt.ReplaceOne("[住院号_提示" & j & "]", "住院号:") wrt.ReplaceOne("[床号_提示" & j & "]", "床号:") wrt.ReplaceOne("[姓名_提示" & j & "]", "姓名:") wrt.ReplaceOne("[主症_提示" & j & "]", "病史_主症:") wrt.ReplaceOne("[现病史_提示" & j & "]", "病史_现病史:") wrt.ReplaceOne("[既往史_提示" & j & "]", "病史_既往史:") wrt.ReplaceOne("[体温_提示" & j & "]", "T:") wrt.ReplaceOne("[血压_提示" & j & "]", "BP:") wrt.ReplaceOne("[呼吸频率_提示" & j & "]", "R:") wrt.ReplaceOne("[脉搏频率_提示" & j & "]", "P:") wrt.ReplaceOne("[记录内容_提示" & j & "]", "记录内容:") wrt.ReplaceOne("[上级医师_提示" & j & "]", "上级医师:") wrt.ReplaceOne("[记录医师_提示" & j & "]", "记录医师:") wrt.ReplaceOne("[换行" & j & "]", chr(13) & chr(13)) Else wrt.ReplaceOne("[记录日期" & j & "]", "") wrt.ReplaceOne("[住院号" & j & "]", "") wrt.ReplaceOne("[床号" & j & "]", "") wrt.ReplaceOne("[姓名" & j & "]", "") wrt.ReplaceOne("[记录内容" & j & "]", "") wrt.ReplaceOne("[体温" & j & "]", "") wrt.ReplaceOne("[血压" & j & "]", "") wrt.ReplaceOne("[呼吸频率" & j & "]", "") wrt.ReplaceOne("[脉搏频率" & j & "]", "") wrt.ReplaceOne("[上级医师" & j & "]", "") wrt.ReplaceOne("[记录医师" & j & "]", "") wrt.ReplaceOne("[主症" & j & "]", "") wrt.ReplaceOne("[现病史" & j & "]", "") wrt.ReplaceOne("[既往史" & j & "]", "") wrt.ReplaceOne("[记录日期_提示" & j & "]", "") wrt.ReplaceOne("[住院号_提示" & j & "]", "") wrt.ReplaceOne("[床号_提示" & j & "]", "") wrt.ReplaceOne("[姓名_提示" & j & "]", "") wrt.ReplaceOne("[记录内容_提示" & j & "]", "") wrt.ReplaceOne("[体温_提示" & j & "]", "") wrt.ReplaceOne("[血压_提示" & j & "]", "") wrt.ReplaceOne("[呼吸频率_提示" & j & "]", "") wrt.ReplaceOne("[脉搏频率_提示" & j & "]", "") wrt.ReplaceOne("[上级医师_提示" & j & "]", "") wrt.ReplaceOne("[记录医师_提示" & j & "]", "") wrt.ReplaceOne("[主症_提示" & j & "]", "") wrt.ReplaceOne("[现病史_提示" & j & "]", "") wrt.ReplaceOne("[既往史_提示" & j & "]", "") wrt.ReplaceOne("[换行" & j & "]", "") End If Next
wrt.BuildOne(r) \'逐行生成报表 Next wrt.quit
|