我的项目描述如下:
     项目名称:中华美食城(textbox)
     估价日期:2004-9-7(textbox)
     个别因素:(datagrid)
   ------------------------------------------------------------------------------------
    位置|朝向   |结构    |备注
   -----|------------------------------------------------------------------------------
   aaaa |bbbbbb |ccccccc |rrrrrrrrrrrrrrrrrrrrrrr
   -----|-------|--------|------------------------------------------------------------ 
   dddd |eeeeee |fffffff |hhhhhhhhhhhhhhhhhhhhhhh
--------------------------------------------------------------------------------------
上面的数据都是从数据库中读出来的(我用的asp.net开发的OA,后台是vb)
对于"项目名称","估价日期"这样的文本我已经成功的导入到 word中了(用了gotobook)
而对于"个别因素"这样的datagrid里的数据,客户要求在word中形成一样的表格,包含datagrid中的
数据.
我想了两种方案:一、把datagrid的内容直接插入到word中,把datagrid当成一个对象(比如是文本)插入到相应的book处(这只是我想的,好像不太可能实现)
二.用vba来做
    我写的选择表格代码如下:
     Public Sub GoToTheTable(ByVal ntable As Integer)
        Dim missing, what, which, count
        missing = System.Reflection.Missing.Value
        what = Word.WdUnits.wdTable
        which = Word.WdGoToDirection.wdGoToAbsolute
        count = ntable
        oWordApplic.Selection.GoTo(what, which, ntable, missing)
        oWordApplic.Selection.Find.ClearFormatting()
        oWordApplic.Selection.Text = ""
    End Sub
   我做测试的模板中有两个table
   问题:
   1。我测试时数据总是插入到第一个table中,总是插入不到第二个表格中,测试代码如下:
    Dim test As New vbwordapp
        test.vbwordapp()
        test.open(ConfigurationSettings.AppSettings("WordMod") + "table2.dot")
        test.GoToTheTable(2)'我想插入到第二个表格中
        test.GoToRightCell()
        test.inserttext(txt_name_table.Text)
        test.GoToDownCell()
        test.inserttext(txt_name_table.Text)
        test.saveas(ConfigurationSettings.AppSettings("WordDoc") + txt_name_table.Text + ".doc")
        test.quit()
    请问这是为什么?怎么定位word中的表格??
   2。我想使表格中的行数,列数和datagrid中的行列数目一样,怎么动态添加word中的表格的行列数???    以上问题分量较大,远远超过了32分的分值,但是我现在只有这么多了,以后有分一定给大家加上。
    上面的问题,大家在做asp.net的OA的时候会遇到,对大家很有参考价值!
    请大家不吝赐教,谢谢大家了!!!!!!!!!!!!