VB 窗体内的数据怎么输出报告到word中 15
悬赏分:100VB窗体内的数据怎么输出报告到word中,我在form1、2等里面有text1,2,3,4以及msflexgrid1,2等,现在我点击Cmd按钮,就可以把这...
悬赏分:100
VB 窗体内的数据怎么输出报告到word中,我在form1、2等里面有text1,2,3,4以及msflexgrid1,2等,现在我点击Cmd按钮,就可以把这些text的数据按顺序放到word的表格中,msflexgrid1,2里的数据按照表格的形式输出。最后形成一个word文档报告?
高手们请帮做一下,需要详细代码?
或者例子!
问题补充:需要一个详细的例子
那些引用word.application对象我都会 关键是我怎么把这些东西写到word的表格里!?
最好高手能给一些代码 ! 展开
VB 窗体内的数据怎么输出报告到word中,我在form1、2等里面有text1,2,3,4以及msflexgrid1,2等,现在我点击Cmd按钮,就可以把这些text的数据按顺序放到word的表格中,msflexgrid1,2里的数据按照表格的形式输出。最后形成一个word文档报告?
高手们请帮做一下,需要详细代码?
或者例子!
问题补充:需要一个详细的例子
那些引用word.application对象我都会 关键是我怎么把这些东西写到word的表格里!?
最好高手能给一些代码 ! 展开
1个回答
展开全部
Private Sub cmdword_Click()
Dim sqlstr As String
Dim rpTitle As String
Set db = OpenDatabase("students.mdb")
sqlstr = "select * from Info"
rpTitle = "通讯录"
Call GenerateReport(sqlstr, rpTitle)
End Sub
---------------------------------------------------------------
Private Sub GenerateReport(sqlstr As String, rpTitle As String)
Dim app As New Word.Application
Dim doc As Word.Document
Dim sel As Word.Selection
Dim tbl As Word.Table
Dim RD As Recordset
Dim i, j As Integer
app.Visible = True
app.Documents.Add
docname = app.ActiveDocument.Name
Set doc = app.Documents(docname)
Set courseinfo = db.OpenRecordset(sqlstr, dbOpenSnapshot, ReadOnly)
Set sel = app.Selection
With sel
.Font.Size = 30
.Font.Bold = True
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.InsertAfter rpTitle
.InsertParagraphAfter
.InsertParagraphAfter
.EndOf
End With
sel.Font.Size = 10
If courseinfo.RecordCount > 0 Then
courseinfo.MoveLast
sel.MoveEnd
Set tbl = sel.Tables.Add(sel.Range, courseinfo.RecordCount + 1, courseinfo.Fields.Count)
tbl.AutoFormat (36)
tbl.AllowAutoFit = True
tbl.Columns.AutoFit
With tbl
courseinfo.MoveFirst
For j = 1 To .Columns.Count
.Cell(1, j).Range.Font.Bold = True
.Cell(1, j).Range.Text = courseinfo.Fields(j - 1).Name
Next j
For i = 2 To .Rows.Count
For j = 1 To .Columns.Count
.Cell(i, j).Range.Text = courseinfo.Fields(j - 1).Value
Next j
courseinfo.MoveNext
Next i
End With
Else
MsgBox "no record!!!", vbOKOnly
End If
sel.GoToNext (wdGoToTable)
sel.Document.Range.InsertParagraphAfter
sel.Document.Range.InsertAfter Date
courseinfo.Close
End Sub
Dim sqlstr As String
Dim rpTitle As String
Set db = OpenDatabase("students.mdb")
sqlstr = "select * from Info"
rpTitle = "通讯录"
Call GenerateReport(sqlstr, rpTitle)
End Sub
---------------------------------------------------------------
Private Sub GenerateReport(sqlstr As String, rpTitle As String)
Dim app As New Word.Application
Dim doc As Word.Document
Dim sel As Word.Selection
Dim tbl As Word.Table
Dim RD As Recordset
Dim i, j As Integer
app.Visible = True
app.Documents.Add
docname = app.ActiveDocument.Name
Set doc = app.Documents(docname)
Set courseinfo = db.OpenRecordset(sqlstr, dbOpenSnapshot, ReadOnly)
Set sel = app.Selection
With sel
.Font.Size = 30
.Font.Bold = True
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.InsertAfter rpTitle
.InsertParagraphAfter
.InsertParagraphAfter
.EndOf
End With
sel.Font.Size = 10
If courseinfo.RecordCount > 0 Then
courseinfo.MoveLast
sel.MoveEnd
Set tbl = sel.Tables.Add(sel.Range, courseinfo.RecordCount + 1, courseinfo.Fields.Count)
tbl.AutoFormat (36)
tbl.AllowAutoFit = True
tbl.Columns.AutoFit
With tbl
courseinfo.MoveFirst
For j = 1 To .Columns.Count
.Cell(1, j).Range.Font.Bold = True
.Cell(1, j).Range.Text = courseinfo.Fields(j - 1).Name
Next j
For i = 2 To .Rows.Count
For j = 1 To .Columns.Count
.Cell(i, j).Range.Text = courseinfo.Fields(j - 1).Value
Next j
courseinfo.MoveNext
Next i
End With
Else
MsgBox "no record!!!", vbOKOnly
End If
sel.GoToNext (wdGoToTable)
sel.Document.Range.InsertParagraphAfter
sel.Document.Range.InsertAfter Date
courseinfo.Close
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |