以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  修改代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=80603)

--  作者:ayiken
--  发布时间:2016/1/27 10:51:00
--  修改代码

老师好!

请帮我修改一下代码

原代码有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
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


--  作者:大红袍
--  发布时间:2016/1/27 12:45:00
--  
上传例子测试啊,
--  作者:ayiken
--  发布时间:2016/1/27 17:05:00
--  
文件太大,上传不了,请帮我修改一楼的代码,就取消保护那一块就行了
--  作者:大红袍
--  发布时间:2016/1/27 17:10:00
--  
无语,以前说过啊,不会做做个例子上来。
--  作者:大红袍
--  发布时间:2016/1/27 17:12:00
--  

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.show