Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共9 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:如何在word增加的行中输入对应的内容

1楼
lxhmax 发表于:2023/9/6 14:46:00
Dim app As New MSWord.Application
try
    Dim doc = app.Documents.Open("D:\Users\Administrator\Desktop\123.docx")
    Dim dt As DataTable = DataTables("表A")
    
    
    For Each r As DataRow In dt.DataRows
        Dim newRow As Row = doc.Content.Tables(2).Rows.Add()
        newRow.Cells(1).Range.Text = r("第一列")
        newRow.Cells(2).Range.Text = r("第二列")
        newRow.Cells(3).Range.Text = r("第三列")
    Next Row
    
    app.Visible = True
catch ex As exception
    msgbox(ex.message)
    app.Quit
End try

老师,请问在word中增加的行中如何输入对应的内容,以上代码报错,麻烦看下要怎么写,谢谢啦

2楼
有点蓝 发表于:2023/9/6 14:59:00
参考:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=76027

word的用法比较特殊,不是按单元格赋值的,需要模拟手工输入,比如app.Selection.TypeText
3楼
lxhmax 发表于:2023/9/6 15:14:00
那个看过了,没看明白,可以指导下修改我上面的代码实现吗?
4楼
有点蓝 发表于:2023/9/6 15:17:00
dim ss() as string = {"第一列",第二列"",...} 
   For Each dr As DataRow In dt.DataRows
        For Each s As string In ss
            app.Selection.TypeText(Text:=dr(s))
            app.Selection.MoveRight(Unit:=12)
        Next
    Next
5楼
lxhmax 发表于:2023/9/6 15:27:00
老师,在word中有2个表格,这个内容可以指定增加到第二个表格中吗?第一行是标题,从第二行开始输入内容
6楼
有点蓝 发表于:2023/9/6 15:48:00
选中第二个表格,然后在输入即可

doc.Tables(2).select
dim ss() as string = {"第一列",第二列"",...} 
   For Each dr As DataRow In dt.DataRows
[此贴子已经被作者于2023/9/6 15:48:01编辑过]
7楼
lxhmax 发表于:2023/9/7 14:26:00
老师,第一行是标题,跳过第一行,从第二行开始输入内容要怎么写?
8楼
有点蓝 发表于:2023/9/7 14:38:00
搞错了。可以按单元格赋值

Dim app As New MSWord.Application
try
    Dim doc = app.Documents.Open("D:\Users\Administrator\Desktop\123.docx")
    Dim dt As DataTable = DataTables("表A")
    
    
    For Each r As DataRow In dt.DataRows
        Dim newRow As object = doc.Content.Tables(2).Rows.Add()
        newRow.Cells(1).Range.Text = r("第一列")
        newRow.Cells(2).Range.Text = r("第二列")
        newRow.Cells(3).Range.Text = r("第三列")
    Next
    
    app.Visible = True
catch ex As exception
    msgbox(ex.message)
    app.Quit
End try
9楼
lxhmax 发表于:2023/9/7 14:55:00
谢谢老师,可以了
共9 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03223 s, 2 queries.