用数据填充词表 [英] Populating Word Table with Data

查看:61
本文介绍了用数据填充词表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



尝试通过vb.net app(或以编程方式)填充单词表但遇到一些困难。数据正在标题的第一列而不是标题后的第一行填充。有没有办法确定从哪里开始填充表格?以下是代码示例:

Hello,

Attempting to populate a word table via vb.net app (or programmatically) but having some difficulty. The data is being populated in the first column of the heading rather than the first row following the heading. Is there a way to determine where to start populating the table? Here's a sample of the code:

Dim sData As String = ""

Do While Not .EOF
sData = sData & .Fields("transaction_date") & vbTab & .Fields("transaction_desc") & vbTab & .Fields("time_billed") & vbCr
Loop

moWordDoc.Tables.Item(iTableNum).Range.Text = sData
        moWordDoc.Tables.Item(iTableNum).Range.ConvertToTable(Separator:=WdTableFieldSeparator.wdSeparateByTabs, _
                                                              AutoFitBehavior:=WdAutoFitBehavior.wdAutoFitFixed, _
                                                              DefaultTableBehavior:=WdDefaultTableBehavior.wdWord8TableBehavior)







The data is taken from an ADO.Net Dataset and stored into an tab-delimited string. The string is assigned to a Word table's Range to be converted into the table.

Any help is appreciated

推荐答案

感谢您的回复。非常感谢。在过去,我使用的是您建议的方法,但是,当DataSet中的记录数超过Word表中的预设行数时,我遇到了问题,因此必须动态添加行。这不仅会降低性能,还会过度填充或超出表格的其他部分。例如,Word表格中有一个或多个列用于列出服务或产品,而这些行下面是这些产品或服务的总金额(与任何其他发票一样)。但是,当必须添加其他行时,要列出产品,它会超出总金额部分。以下是代码示例:



Thanks for the reply. It's appreciated. In the past, I was using the methodology you suggest, however, I ran into problems when the number of records in a DataSet exceeded the number of preset rows in the Word table, whereby rows had to added on the fly. This not only slowed the performance but also over-filled or over-ran other portions of the table. For example, the Word table has a section or rows for listing services or products and below those rows is the total amount for those products or services (like any other invoice). However, when additional rows have to be added, to list products, it overruns the total amount section. Here's a sample of the code:

With moWordDoc.Tables.Item(iTableNum)
    Do While Not moAdoSql.EOF
        RowCnt = RowCnt + 1
                If RowCnt > .Rows.Count - iNumOfRowsBeforeInsert Then
                    .Rows.Add(.Rows.Item(RowCnt - 1))
                End If

                .Cell(RowCnt - 1, COL_date).Range.Text = VB6.Format(NullToString(moAdoSql.Fields("transaction_date")), gcFORMAT_ShortDate)
                .Cell(RowCnt - 1, COL_desc).Range.Text = NullToString(moAdoSql.Fields("transaction_desc"))
                .Cell(RowCnt - 1, COL_time).Range.Text = NullToString(moAdoSql.Fields("time_billed"))
moAdoSql.MoveNext()
            Loop
        End With





因此,根据微软文章http://msdn.microsoft.com/en-us/library/aa537149(v=office.11​​).aspx,我正在尝试使用ConvertToTable方法。





任何帮助表示赞赏。



As a result, per Microsoft article, http://msdn.microsoft.com/en-us/library/aa537149(v=office.11).aspx, I'm trying to use the ConvertToTable method.


Any help is appreciated.


你好,


通过更新2003年和2007年到2010年的模板文件解决了这个问题。我为麻烦道歉。再次感谢所有的建议和意见。非常感谢。



亲切的问候,
Hello,

The problem has been solved by updating the template files from 2003 and 2007 to 2010. My apologies for the hassle. Thanks again for all of the suggestions and input. It is appreciated.

Kind regards,


这篇关于用数据填充词表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆