| 发表于:2007-02-06 11:46:273楼 得分:50 |
'插入表格 public sub inserttable(byref table as datatable) dim otable as word.table dim rowindex, colindex, numrows, numcolumns as integer rowindex = 1 colindex = 0 if (table.rows.count = 0) then exit sub end if numrows = table.rows.count + 1 numcolumns = table.columns.count otable = odocument.tables.add(owordapplic.selection.range(), numrows, numcolumns) '初始化列 dim row as datarow dim col as datacolumn 'for each col in table.columns ' colindex = colindex + 1 ' otable.cell(1, colindex).range.insertafter(col.columnname) 'next '将行添入表格 for each row in table.rows rowindex = rowindex + 1 colindex = 0 for each col in table.columns colindex = colindex + 1 otable.cell(rowindex, colindex).range.insertafter(row(col.columnname)) next next otable.rows(1).delete() otable.allowautofit = true otable.applystylefirstcolumn = true otable.applystyleheadingrows = true end sub '插入表格(修改为在原有表格的基础上添加数据) public sub inserttable2(byref table as datatable, byval strbmerge as string, byval totalrow as integer) dim otable as word.table dim rowindex, colindex, numrows, numcolumns as integer dim strm() as string dim i as integer rowindex = 1 colindex = 0 if (table.rows.count = 0) then exit sub end if numrows = table.rows.count + 1 numcolumns = table.columns.count 'otable = odocument.tables.add(owordapplic.selection.range(), numrows, numcolumns) '初始化列 dim row as datarow dim col as datacolumn 'for each col in table.columns ' colindex = colindex + 1 ' otable.cell(1, colindex).range.insertafter(col.columnname) 'next '将行添入表格 for each row in table.rows colindex = 0 gotorightcell() owordapplic.selection.insertrows(1) for each col in table.columns gotorightcell() colindex = colindex + 1 try owordapplic.selection.typetext(row(col.columnname)) catch ex as exception owordapplic.selection.typetext( " ") end try 'owordapplic.selection.cell(rowindex, colindex).range.insertafter(row(col.columnname)) next next '如果strbmerge不为空.则要合并相应的行和列 if strbmerge.trim().length <> 0 then strm = strbmerge.split( "; ") for i = 1 to strm.length - 1 if strm(i).split( ", ").length = 2 then mergedouble(totalrow, strm(0), strm(i).split( ", ")(1), strm(i).split( ", ")(0)) end if mergesingle(totalrow, strm(0), strm(i)) next end if '删除可能多余的一行 'gotorightcell() 'gotodowncell() 'owordapplic.selection.rows.delete() 'otable.allowautofit = true 'otable.applystylefirstcolumn = true 'otable.applystyleheadingrows = true end sub '插入表格(专门适应工程结算工程量清单) public sub inserttableqd(byref table as datatable, byref table1 as datatable) dim otable as word.table dim rowindex, colindex, numrows, numcolumns as integer dim xmmc as string dim i as integer dim j as integer rowindex = 1 colindex = 0 if (table.rows.count = 0) then exit sub end if numrows = table.rows.count + 1 numcolumns = table.columns.count 'otable = odocument.tables.add(owordapplic.selection.range(), numrows, numcolumns) '初始化列 dim row as datarow dim rowtemp as datarow dim row1() as datarow dim col as datacolumn dim coltemp as datacolumn 'for each col in table.columns ' colindex = colindex + 1 ' otable.cell(1, colindex).range.insertafter(col.columnname) 'next '将行添入表格 for each row in table.rows colindex = 0 xmmc = row( "项目名称 ") gotorightcell() owordapplic.selection.insertrows(1) for each col in table.columns gotorightcell() try if (col.columnname = "项目序号 ") then owordapplic.selection.typetext(inttoupint(val(row(col.columnname)))) else owordapplic.selection.typetext(row(col.columnname)) end if catch ex as exception owordapplic.selection.typetext( " ") end try 'owordapplic.selection.cell(rowindex, colindex).range.insertafter(row(col.columnname)) next row1 = table1.select( "项目名称= ' " + xmmc + " ' ") for i = 0 to row1.length - 1 gotorightcell() owordapplic.selection.insertrows(1) for j = 0 to table1.columns.count - 1 if (table1.columns(j).columnname <> "项目名称 ") then gotorightcell() try owordapplic.selection.typetext(row1(i)(j)) catch ex as exception owordapplic.selection.typetext( " ") end try end if 'owordapplic.selection.cell(rowindex, colindex).range.insertafter(row(col.columnname)) next next next '删除可能多余的一行 'gotorightcell() 'gotodowncell() 'owordapplic.selection.rows.delete() 'otable.allowautofit = true 'otable.applystylefirstcolumn = true 'otable.applystyleheadingrows = true end sub '插入表格,为了满足要求,在中间添加一根竖线 public sub inserttable3(byref table as datatable, byval introw as integer, byval intcol as integer) dim rowindex, colindex, numrows, numcolumns as integer dim row as datarow dim col as datacolumn if (table.rows.count = 0) then exit sub end if '首先是拆分选中的单元格 odocument.tables(1).cell(introw, 3).split(table.rows.count, 2) '选中初始的单元格 odocument.tables(1).cell(introw, 3).select() '将行添入表格 for each row in table.rows try odocument.tables(1).cell(introw, 3).range.insertafter(row(0)) odocument.tables(1).cell(introw, 4).range.insertafter(row(1)) catch ex as exception odocument.tables(1).cell(introw, 3).range.insertafter( " ") odocument.tables(1).cell(introw, 4).range.insertafter( " ") end try introw = introw + 1 next end sub | | |
|