标题:[求助]如何在word中控制记录换行
取消只看楼主
djccit
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2005-12-26
 问题点数:0 回复次数:0 
[求助]如何在word中控制记录换行

如何在word中控制记录换行


另外这段程序运行后,为什么记录没有能够送入到word中,请朋友们帮我看看

Public conn As ADODB.Connection
Dim str As New ADODB.Recordset


Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim ifieldcount As Integer, irecordcount As Integer

Dim wdapp As Word.Application
Dim wddoc As Word.Document
Dim atable As Word.Table
With str
.MoveLast
.MoveFirst
ifieldcount = .Fields.Count
irecordcount = .RecordCount
End With

On Error Resume Next
'创建word应用程序,打开word2003
Set wdapp = CreateObject("Word.Application")
'在word中添加一个新文档
Set wddoc = wdapp.Documents.Add
With wdapp
.Visible = True
.Activate
'在word中增加一个表格
Set stable = .ActiveDocument.Tables.Add(.Selection.Range, irecordcount + 1, ifieldcount)
For i = 0 To ifieldcount - 1
atable.Cell(1, i + 1).Range.InsertAfter DataGrid1.Columns(i)
Next i
'指定表格内容
str.MoveFirst
For i = 0 To irecordcount - 1
For j = 0 To ifieldcount - 1
atable.Cell(i + 2, j + 1).Range.InsertAfter str.Fields(j)
Next j
str.MoveNext
Next i

End With
'清除word 对象
Set wdapp = Nothing
Set wddoc = Nothing


End Sub

Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" _
+ "User ID=sa;password=sa;Initial Catalog=ComSys;Data Source=127.0.0.1"
conn.Open

strsql = "select 编号,货物编号,货物名称,计量单位,经办人,出库时间,出库单价,出库数量,金额,客户,存放仓库,备注 from out_warehouse"
Set str = New ADODB.Recordset
If str.State = adStateOpen Then str.Close

str.CursorLocation = adUseClient
str.Open strsql, conn, adOpenStatic, adLockBatchOptimistic

Set DataGrid1.DataSource = str

End Sub


[此贴子已经被作者于2006-6-17 18:56:54编辑过]

搜索更多相关主题的帖子: word中 Dim Integer Word str 
2006-06-17 14:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-72969-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.872536 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved