如何在vb中显示固定的word表格,并从access数据库中把需要的数据填入表格中固定的地方,并最后实现打印?请高手帮忙啊,就是我有一个固定的word空白表格模板,通过查找操作把access数据库中所需要的数据添充到word表格中,并最后实现打印。打印后,word表格依然保持空白状态。
谢谢啦 。

解决方案 »

  1.   

    参考:http://www.xrss.cn/Dev/VB/200741412388.Html
      

  2.   

    看我发的贴,希望对你有帮助.
    http://topic.csdn.net/u/20080805/10/e258a7fe-6302-435f-87e7-8da26c91e95f.html
      

  3.   

    private sub Command1Click() 
    Dim i As Integer 
    Dim ifieldcount As Integer 
    Dim ircordcount As Integer 
    Dim wdapp As Word.Application 
    Dim wddoc As Word.Document 
    Dim atable As Word.Table 
    Set wdapp = CreateObject("Word.Application") 
    Set wddoc = wdapp.Documents.Add 
    ircordcount = Adodc1.Recordset.RecordCount 
    wdapp.Visible = True 
    wdapp.Activate 
    Set atable = wdapp.ActiveDocument.Tables.Add(wdapp.Selection.Range, ircordcount + 1, 8)'这里表示行数和列数。ircordcount + 1是行数,因为要有表头多以行数要比记录数多一行,列数为8,有多少字段就要多少列 atable.Cell(1, 1).Range.InsertAfter "字段1" 
    atable.Cell(1, 2).Range.InsertAfter "字段2" 
    atable.Cell(1, 3).Range.InsertAfter "字段3" 
    atable.Cell(1, 4).Range.InsertAfter "字段4" 
    atable.Cell(1, 5).Range.InsertAfter "字段5" 
    atable.Cell(1, 6).Range.InsertAfter "字段6" 
    atable.Cell(1, 7).Range.InsertAfter "字段7" 
    atable.Cell(1, 8).Range.InsertAfter "字段8" 
    If Adodc1.Recordset.RecordCount > 0 Then 
    ircordcount = Adodc1.Recordset.RecordCount 
    Adodc1.Recordset.MoveFirst 
    Do While Adodc1.Recordset.AbsolutePosition <> adPosEOF 
    atable.Cell(DataGrid1.Book + 1, 1).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 2).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 3).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 4).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 5).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 6).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 7).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 8).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    Adodc1.Recordset.MoveNext 
    Loop 
    If Adodc1.Recordset.AbsolutePosition = adPosEOF Then 
    atable.Cell(DataGrid1.Book + 1, 1).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 2).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 3).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 4).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 5).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 6).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 7).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    atable.Cell(DataGrid1.Book + 1, 8).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" 
    End If 
    Set wdapp = Nothing 
    Set wddoc = Nothing 
    Else 
    MsgBox "没有可显示记录", , "提示" 
    End If 
    end sub别忘了在工程——引用里面把word勾上