| 发表于:2007-04-10 11:42:42 楼主 |
public function kstzbaob() dim app as new word.application dim doc as word.document dim tabl1 as word.table dim tabl2 as word.table dim rd as recordset dim sel as word.selection dim i, j as integer adodc1.recordset.movefirst tsform.show app.documents.open ( "d:\li\vb\焊工管理系统\焊工考试通知 ") 表示打开文档对象集的一个文档 set sel = app.selection 表示sel为一个选中的文本 sel.moveright unit:=wdword, count:=5 sel.text = "hk " & adodc1.recordset.fields( "计划编号 ") sel.movedown unit:=wdline, count:=1 sel.text = adodc1.recordset.fields( "单位 ") & ": " sel.movedown unit:=wdparagraph, count:=1 sel.moveright unit:=wdword, count:=5 sel.text = adodc1.recordset.fields( "考试日期 ") - 1 sel.moveright unit:=wdword, count:=17 sel.text = adodc1.recordset.fields( "考试日期 ") sel.movedown unit:=wdparagraph, count:=2 '按考试信息生成word表格并设置属性 set tabl1 = sel.tables.add(sel.range, adodc1.recordset.recordcount + 1, 6) tabl1.autoformat (36) tabl1.allowautofit = true tabl1.columns.autofit tabl1.borders.outsidelinestyle = wdlinestylesingle tabl1.borders.outsidelinewidth = wdlinewidth150pt tabl1.columns(1).width = 40 tabl1.columns(2).width = 40 tabl1.columns(3).width = 120 tabl1.columns(4).width = 30 tabl1.columns(5).width = 50 tabl1.columns(6).width = 80 tabl1.leftpadding = 0 tabl1.rightpadding = 0 tabl1.autofitbehavior (wdautofitwindow) '将满足条件的记录写入word表格 with tabl1 adodc1.recordset.movefirst for j = 1 to tabl1.columns.count .cell(1, j).range.font.bold = true next j .cell(1, 1).range.text = "考试号 " .cell(1, 2).range.text = "姓 名 " .cell(1, 3).range.text = "培 考 项 目 " .cell(1, 4).range.text = "性质 " .cell(1, 5).range.text = "工位号 " .cell(1, 6).range.text = "理论考试 " for i = 2 to tabl1.rows.count if adodc1.recordset.fields( "考试号 ") <> " " then .cell(i, 1).range.text = adodc1.recordset.fields( "考试号 ") else: .cell(i, 1).range.text = " " end if if adodc1.recordset.fields( "姓名 ") <> " " then .cell(i, 2).range.text = adodc1.recordset.fields( "姓名 ") else: .cell(i, 2).range.text = " " end if if adodc1.recordset.fields( "考试项目 ") <> " " then .cell(i, 3).range.text = adodc1.recordset.fields( "考试项目 ") else: .cell(i, 3).range.text = " " end if if adodc1.recordset.fields( "考试性质 ") <> " " then .cell(i, 4).range.text = adodc1.recordset.fields( "考试性质 ") else: .cell(i, 4).range.text = " " end if if adodc1.recordset.fields( "工位 ") <> " " or adodc1.recordset.fields( "技能场次 ") <> " " then .cell(i, 5).range.text = adodc1.recordset.fields( "工位 ") & "- " & adodc1.recordset.fields( "技能场次 ") else: .cell(i, 5).range.text = " " end if if adodc1.recordset.fields( "理论日期 ") <> " " or adodc1.recordset.fields( "理论考试场次 ") <> " " then if adodc1.recordset.fields( "理论日期 ") <> "3000-1-1 " then .cell(i, 6).range.text = adodc1.recordset.fields( "理论日期 ") & "上午 " & adodc1.recordset.fields( "理论考试场次 ") else: .cell(i, 6).range.text = " " end if else: .cell(i, 6).range.text = " " end if adodc1.recordset.movenext if adodc1.recordset.eof then adodc1.recordset.movelast end if next i end with ' sel.movedown unit:=wdline, count:=adodc1.recordset.recordcount + 2 sel.movedown unit:=wdline, count:=1 sel.movedown unit:=wdparagraph, count:=1 'sel.movedown unit:=wdline, count:=1 '按考试项目生成表格并将数据写入表格 set tabl2 = sel.tables.add(sel.range, adodc2.recordset.recordcount + 1, 4) tabl2.autoformat (36) tabl2.allowautofit = true tabl2.columns.autofit tabl2.borders.outsidelinestyle = wdlinestylesingle tabl2.borders.outsidelinewidth = wdlinewidth150pt tabl2.columns(1).width = 120 tabl2.columns(2).width = 80 tabl2.columns(3).width = 120 tabl2.columns(4).width = 80 tabl2.leftpadding = 0 tabl2.rightpadding = 0 tabl2.autofitbehavior (wdautofitwindow) with tabl2 .cell(1, 1).range.font.bold = true .cell(1, 2).range.font.bold = true .cell(1, 3).range.font.bold = true .cell(1, 4).range.font.bold = true .cell(1, 1).range.text = "考试项目 " .cell(1, 2).range.text = "wi 号 " .cell(1, 3).range.text = "母材及规格 " .cell(1, 4).range.text = "焊材及规格 " adodc2.recordset.movefirst for i = 2 to tabl2.rows.count if adodc2.recordset.fields( "考试项目 ") <> " " then .cell(i, 1).range.text = adodc2.recordset.fields( "考试项目 ") else: .cell(i, 1).range.text = " " end if if adodc2.recordset.fields( "wi ") <> " " then .cell(i, 2).range.text = adodc2.recordset.fields( "wi ") else: .cell(i, 2).range.text = " " end if if adodc2.recordset.fields( "母材 ") <> " " or adodc2.recordset.fields( "母材1规格 ") <> " " or adodc2.recordset.fields( "母材2规格 ") <> " " then .cell(i, 3).range.text = adodc2.recordset.fields( "母材 ") & " " & adodc2.recordset.fields( "母材1规格 ") & adodc2.recordset.fields( "母材2规格 ") else: .cell(i, 3).range.text = " " end if if adodc2.recordset.fields( "焊材及规格 ") <> " " or adodc2.recordset.fields( "焊剂 ") <> " " then .cell(i, 4).range.text = adodc2.recordset.fields( "焊材及规格 ") & " " & adodc2.recordset.fields( "焊剂 ") else: .cell(i, 4).range.text = " " end if adodc2.recordset.movenext if adodc2.recordset.eof then adodc2.recordset.movelast end if next i end with sel.movedown 5, adodc2.recordset.recordcount + 1 sel.movedown unit:=wdparagraph, count:=3 sel.moveright unit:=wdword, count:=13 sel.text = date tsform.hide app.visible = true end function |
|
|
|
|