CSDN博客

img qzr820

vb.net2005 利用创建好的WORD模板制作WORD报表

发表于2008/9/28 9:26:00  1345人阅读

       Dim WordAPP As New Word.Application
        Dim WordDocument As Word.Document
        WordDocument = WordAPP.Documents.Open(Application.StartupPath & "/report.doc")
        WordDocument.Activate()

     '进行查找替换

        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C1"
            .Replacement.Text = "小样门诊室"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With

        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C2"
            .Replacement.Text = "小样路"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With

        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C3"
            .Replacement.Text = "小样"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With

        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C4"
            .Replacement.Text = "1100101010"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With

        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C5"
            .Replacement.Text = "药品项目^l检查项目"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With
        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C6"
            .Replacement.Text = "小草^l手术费"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With
        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C7"
            .Replacement.Text = "10^l5"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With
        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C8"
            .Replacement.Text = "2^l1"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With
        With WordAPP.Selection.Find
            .ClearFormatting()
            .Replacement.ClearFormatting()
            .Text = "C9"
            .Replacement.Text = "20^l5"
            .MatchCase = True
            .Execute(, , , , , , , , , , Word.WdReplace.wdReplaceAll)
        End With

        WordAPP.Visible = True

'^l为手动换行符 1为字母L 也以换个两个数字1 换成数字后如果后面跟数字可能会有点问题。所以建议使用字母

'^p为硬回车

图1为没有替换这前的模板内容

图2为替换了内容后的文档

 

0 0

相关博文

我的热门文章

img
取 消
img