| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 703 人关注过本帖
标题:[求助]如何在word中控制记录换行
只看楼主 加入收藏
djccit
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2005-12-26
收藏
 问题点数:0 回复次数:1 
[求助]如何在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
tang688
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1219
专家分:35
注 册:2004-12-25
收藏
得分:0 
哈哈,可以问这一个这个WORD用什么控件?
还是你在WORD里用VBA?

2006-06-17 19:19
快速回复:[求助]如何在word中控制记录换行
数据加载中...
 
   



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

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