看word本身的文档,上面有的选择帮助,上面有VBA声明word的接口,我想你一定可以找到你要的东西的!

解决方案 »

  1.   

    http://www.djpate.freeserve.co.uk/Automation.htm
    上面有在Delphi中操作word的例子
      

  2.   

    var
        Word:Variant;
    begin
        Word:=CreateOLeObject('Word.application');
        //用VBa操作word
        //如:Word.documents.add;
        Word.quit;//退出
    end;
      

  3.   

    christian_dindin(石之轩) 
    其中有一个books,但我在d6上他提示找不到word_tlb.dcu,该如何?我不能运行此程序,不知结果是否和我想要的一样?
      

  4.   

    netlib(河外孤星)我要向文字型窗体域中填写数据,用数据库中数据。
      

  5.   

    方法有多种。
    我说两种思路罢:
    1、在程序中打开WORD,并将WORD的VBA代码转换成Delphi代码执行,就象在WORD中操作一样;这种方法速度稍慢,可用于处理数据量小,而且出现的频率高的报表。
    2、在程序中打开WORD,并运行WORD的中宏(这个宏已事先被建立),运行时所需的数据可以从临时文件中读取。下面是这个读文件的宏的一个简单例子:Sub Macro1()
    '
    '这个宏用来读取文件
    '并将文件内容经处理后写入文档
    '
    '文件中每行三个字符串,中间用TAB键分开,结尾用换行符    Dim fs As Object
        Dim f As Object
        Dim i, j As Integer
        Dim ss, s1, s2, s3 As String
            
        Selection.HomeKey Unit:=wdStory
        Selection.MoveDown Unit:=wdLine, Count:=5, Extend:=wdExtend
        Selection.Copy
        Selection.HomeKey Unit:=wdStory
        
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.OpenTextFile("d:\test.txt", 1, TristateFalse)
        
        With ActiveDocument.Books
                .DefaultSorting = wdSortByLocation
                .ShowHidden = False
        End With
            
        ss = " "
        
        Selection.Find.ClearFormatting
        With Selection.Find
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With    Do
            ss = f.ReadLine
            
            i = Pos(ss, Chr(9), 1)
            j = Pos(ss, Chr(9), i)
            If i <> 0 And j <> 0 Then
                s1 = Left(ss, i - 1)
                s2 = Mid(ss, i + 1, j - i - 1)
                s3 = Right(ss, Len(ss) - j)
            Else
                s1 = ""
                s2 = ""
                s3 = ""
            End If
            
            Selection.Find.Text = "姓名"
            Selection.Find.Execute
            Selection.MoveRight Unit:=wdCharacter, Count:=2
            Selection.TypeText (s1)
            
            Selection.Find.Text = "性别"
            Selection.Find.Execute
            Selection.MoveRight Unit:=wdCharacter, Count:=2
            Selection.TypeText (s2)
            
            Selection.Find.Text = "年龄"
            Selection.Find.Execute
            Selection.MoveRight Unit:=wdCharacter, Count:=2
            Selection.TypeText (s3)
            Selection.TypeParagraph
                        
            Selection.Paste
            Selection.MoveUp Unit:=wdLine, Count:=3
            Selection.HomeKey
            
            If f.AtEndofStream = True Then Exit Do
        Loop
        
        Selection.HomeKey Unit:=wdLine
        Selection.MoveUp Unit:=wdLine, Count:=3, Extend:=wdExtend
        Selection.Delete
        
        f.Close
        
    End SubPublic Function Pos(ByVal source As String, ByVal substr As String, ByVal start As Integer) As Integer
    Dim i As IntegerPos = 0
    For i = start + 1 To Len(source)
        If Mid(source, i, Len(substr)) = substr Then
            Pos = i
            Exit Function
        End If
    Next iEnd Function
      

  6.   

    对,你先在你的模板中做好标志,然后通过查找——替换完成
    我先在多一个办公平台的公文成文就是这样做的。
    给你段大概的代码:Word替换标记字符串要使用WordDocument.Range.Find.Execute
    下面的例子中用“Delphi”替换了“VB”: 
    var 
    FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, 
    MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace: OleVariant; 
    begin 
    FindText := 'VB'; 
    MatchCase := False; 
    MatchWholeWord := True; 
    MatchWildcards := False; 
    MatchSoundsLike := False; 
    MatchAllWordForms := False; 
    Forward := True; 
    Wrap := wdFindContinue; 
    Format := False; 
    ReplaceWith := 'Delphi'; 
    Replace := True; WordDocument.Range.Find.Execute( FindText, MatchCase, MatchWholeWord, 
    MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, 
    Wrap, Format, ReplaceWith, Replace ); 说明:你只要定义好FindText 在Word模板中就可以了!有问题给我发短信息
      

  7.   

    yjs_lh(长风浪子),wenzm(再也不做驴的驴子)
    合同的头和尾可以用find找到和替换,中间的表格中的数据又如何,且数据纪录条数每次不一样
      

  8.   

    yjs_lh(长风浪子),wenzm(再也不做驴的驴子)
    合同的头和尾可以用find找到和替换,中间的表格中的数据又如何,且数据纪录条数每次不一样
      

  9.   


      可以在文档中对你的表格定位
    WordDocument.Tables.items[].Cell[][]看到了吗?可以单个格子操作!
      
     
      

  10.   

    你还可以对Talbe增加行和列的操作
    如果你不知道VBA怎么写,告诉你个方法
    你启动Word宏录制然后用手工的方法去增加行或列
    之后查看录制的宏,你就可以看到对应的代码了!