下面的代码转换成VBS语法就OK了'生成照相检验文书
Public Function CheckUpPhoto(CheckUpID As Variant, BookTitles As Variant, SessionID As Variant, userid As Variant, Optional Columns As Variant = 2, Optional Rows As Variant = 2) As Variant
Dim oWordApp As New Word.Application
Dim oWordDoc As Word.Document
Dim oTable As Word.Table, oDetailTable As Word.Table
Dim oCell As Word.Cell
Dim oRange As Word.Range
Dim stm As New ADODB.Stream
Dim fso As New FileSystemObject
Dim strSQL As String, i As Integer
On Error GoTo errorhandle
If Trim(BookTitles) = "" Then
BookTitles = "照相检验文书"
End If
oWordApp.Visible = False
Set oWordDoc = oWordApp.Documents.Add
oWordDoc.Select
oWordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
oWordApp.Selection.Font.Bold = True
oWordApp.Selection.Font.Size = 25
oWordApp.Selection.TypeText Text:=BookTitles
strSQL = "SELECT id,kind,description,matternum,recordman,recordtime,resultpic"
strSQL = strSQL & " FROM tblcheckuppic WHERE checkupid='" & CheckUpID & "' ORDER BY recordtime ASC"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open db.GetConnString()
conn.CursorLocation = adUseClient
rs.Open strSQL, conn, 3, 3
If Not rs.EOF Then
TableRows = IIf(rs.RecordCount Mod Columns = 0, Int(rs.RecordCount / Columns), Int(rs.RecordCount / Columns) + 1)
Set oTable = oWordDoc.Tables.Add(oWordApp.Selection.Range, TableRows, Columns)
oTable.Rows.AllowBreakAcrossPages = False
oTable.Range.Font.Bold = False
oTable.Range.Font.Size = 10
oTable.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
For i = 1 To rs.RecordCount
Set oCell = oTable.Cell(Int((i - 1) / Columns) + 1, (i - 1) Mod Columns + 1)
oCell.Select
oCell.Range.Text = " "
Set oDetailTable = oCell.Tables.Add(oWordApp.Selection.Range, 4, 3)
oDetailTable.Rows(1).Cells.Merge
oDetailTable.Cell(1, 1).Range.Text = "[" & i & "]"
oDetailTable.Cell(2, 1).Range.Text = rs("kind")
oDetailTable.Cell(2, 2).Merge MergeTo:=oDetailTable.Cell(2, 3)
oDetailTable.Cell(2, 2).Range.Text = rs("matternum")
oDetailTable.Cell(3, 1).Range.Text = rs("recordman")
oDetailTable.Cell(3, 2).Merge MergeTo:=oDetailTable.Cell(3, 3)
oDetailTable.Cell(3, 2).Range.Text = rs("recordtime")
oDetailTable.Cell(4, 1).Range.Text = rs("description")
If Not IsNull(rs("resultpic")) Then
AttachmentFile = App.Path & "\" & SessionID & "_PICTURE[" & i & "].JPG"
stm.Mode = adModeReadWrite
stm.Type = adTypeBinary
stm.Open
stm.Write rs("resultpic")
stm.SaveToFile AttachmentFile, 2
stm.Close
End If
oDetailTable.Rows(4).Cells.Merge
oDetailTable.Cell(4, 1).Range.InlineShapes.AddPicture AttachmentFile, False, True
If fso.FileExists(AttachmentFile) Then
fso.DeleteFile AttachmentFile
End If
rs.MoveNext
Next
MaxPages = IIf(oTable.Rows.Count Mod Rows = 0, Int(oTable.Rows.Count / Rows), Int(oTable.Rows.Count / Rows) + 1)
For i = 1 To MaxPages - 1
Set oTable = oTable.Split(Rows + 1)
Next
oWordDoc.Select
oWordApp.Selection.GoTo wdGoToTable, wdGoToFirst
For i = 1 To MaxRows - 1
Set oRange = oWordApp.Selection.GoTo(wdGoToTable, wdGoToNext)
oRange.InsertBreak wdPageBreak
oWordApp.Selection.GoTo wdGoToTable, wdGoToNext
Next
SaveFileName = App.Path & "\" & userid & Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now()) & ".doc"
oWordDoc.SaveAs SaveFileName
End If
oWordDoc.Close
rs.Close
If fso.FileExists(SaveFileName) Then
stm.Type = adTypeBinary
stm.Mode = adModeReadWrite
stm.Open
stm.LoadFromFile SaveFileName
strSQL = "SELECT zhuanye FROM tblcheckup WHERE id='" & Trim(CheckUpID) & "'"
rs.Open strSQL, conn
If Not rs.EOF Then
spec = rs("zhuanye")
Else
spec = ""
End If
rs.Close
strSQL = "SELECT * FROM tblbook WHERE zdy1='4' AND id='" & Trim(CheckUpID) & "'"
rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
rs("title") = BookTitles
rs("Lrsj") = Now()
rs("uptype") = "doc"
rs("zdy1") = 4
rs("status") = 1
rs("wjlj").AppendChunk stm.Read
rs.Update
Else
rs.AddNew
rs("jlbh") = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now())
rs("id") = CheckUpID
rs("title") = BookTitles
rs("wjlj").AppendChunk stm.Read
rs("Lrr") = userid
rs("lrsj") = Now()
rs("spleader") = "无需审批"
rs("spec") = spec
rs("spec_no") = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now())
rs("status") = 1
rs("uptype") = "doc"
rs("zdy1") = 4
rs.Update
End If
rs.Close
stm.Close
fso.DeleteFile SaveFileName
End If
conn.Close
errorhandle:
oWordApp.Quit
Set stm = Nothing
Set fso = Nothing
Set oWordDoc = Nothing
Set oWordApp = Nothing
End Function
Public Function CheckUpPhoto(CheckUpID As Variant, BookTitles As Variant, SessionID As Variant, userid As Variant, Optional Columns As Variant = 2, Optional Rows As Variant = 2) As Variant
Dim oWordApp As New Word.Application
Dim oWordDoc As Word.Document
Dim oTable As Word.Table, oDetailTable As Word.Table
Dim oCell As Word.Cell
Dim oRange As Word.Range
Dim stm As New ADODB.Stream
Dim fso As New FileSystemObject
Dim strSQL As String, i As Integer
On Error GoTo errorhandle
If Trim(BookTitles) = "" Then
BookTitles = "照相检验文书"
End If
oWordApp.Visible = False
Set oWordDoc = oWordApp.Documents.Add
oWordDoc.Select
oWordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
oWordApp.Selection.Font.Bold = True
oWordApp.Selection.Font.Size = 25
oWordApp.Selection.TypeText Text:=BookTitles
strSQL = "SELECT id,kind,description,matternum,recordman,recordtime,resultpic"
strSQL = strSQL & " FROM tblcheckuppic WHERE checkupid='" & CheckUpID & "' ORDER BY recordtime ASC"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open db.GetConnString()
conn.CursorLocation = adUseClient
rs.Open strSQL, conn, 3, 3
If Not rs.EOF Then
TableRows = IIf(rs.RecordCount Mod Columns = 0, Int(rs.RecordCount / Columns), Int(rs.RecordCount / Columns) + 1)
Set oTable = oWordDoc.Tables.Add(oWordApp.Selection.Range, TableRows, Columns)
oTable.Rows.AllowBreakAcrossPages = False
oTable.Range.Font.Bold = False
oTable.Range.Font.Size = 10
oTable.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
For i = 1 To rs.RecordCount
Set oCell = oTable.Cell(Int((i - 1) / Columns) + 1, (i - 1) Mod Columns + 1)
oCell.Select
oCell.Range.Text = " "
Set oDetailTable = oCell.Tables.Add(oWordApp.Selection.Range, 4, 3)
oDetailTable.Rows(1).Cells.Merge
oDetailTable.Cell(1, 1).Range.Text = "[" & i & "]"
oDetailTable.Cell(2, 1).Range.Text = rs("kind")
oDetailTable.Cell(2, 2).Merge MergeTo:=oDetailTable.Cell(2, 3)
oDetailTable.Cell(2, 2).Range.Text = rs("matternum")
oDetailTable.Cell(3, 1).Range.Text = rs("recordman")
oDetailTable.Cell(3, 2).Merge MergeTo:=oDetailTable.Cell(3, 3)
oDetailTable.Cell(3, 2).Range.Text = rs("recordtime")
oDetailTable.Cell(4, 1).Range.Text = rs("description")
If Not IsNull(rs("resultpic")) Then
AttachmentFile = App.Path & "\" & SessionID & "_PICTURE[" & i & "].JPG"
stm.Mode = adModeReadWrite
stm.Type = adTypeBinary
stm.Open
stm.Write rs("resultpic")
stm.SaveToFile AttachmentFile, 2
stm.Close
End If
oDetailTable.Rows(4).Cells.Merge
oDetailTable.Cell(4, 1).Range.InlineShapes.AddPicture AttachmentFile, False, True
If fso.FileExists(AttachmentFile) Then
fso.DeleteFile AttachmentFile
End If
rs.MoveNext
Next
MaxPages = IIf(oTable.Rows.Count Mod Rows = 0, Int(oTable.Rows.Count / Rows), Int(oTable.Rows.Count / Rows) + 1)
For i = 1 To MaxPages - 1
Set oTable = oTable.Split(Rows + 1)
Next
oWordDoc.Select
oWordApp.Selection.GoTo wdGoToTable, wdGoToFirst
For i = 1 To MaxRows - 1
Set oRange = oWordApp.Selection.GoTo(wdGoToTable, wdGoToNext)
oRange.InsertBreak wdPageBreak
oWordApp.Selection.GoTo wdGoToTable, wdGoToNext
Next
SaveFileName = App.Path & "\" & userid & Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now()) & ".doc"
oWordDoc.SaveAs SaveFileName
End If
oWordDoc.Close
rs.Close
If fso.FileExists(SaveFileName) Then
stm.Type = adTypeBinary
stm.Mode = adModeReadWrite
stm.Open
stm.LoadFromFile SaveFileName
strSQL = "SELECT zhuanye FROM tblcheckup WHERE id='" & Trim(CheckUpID) & "'"
rs.Open strSQL, conn
If Not rs.EOF Then
spec = rs("zhuanye")
Else
spec = ""
End If
rs.Close
strSQL = "SELECT * FROM tblbook WHERE zdy1='4' AND id='" & Trim(CheckUpID) & "'"
rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
rs("title") = BookTitles
rs("Lrsj") = Now()
rs("uptype") = "doc"
rs("zdy1") = 4
rs("status") = 1
rs("wjlj").AppendChunk stm.Read
rs.Update
Else
rs.AddNew
rs("jlbh") = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now())
rs("id") = CheckUpID
rs("title") = BookTitles
rs("wjlj").AppendChunk stm.Read
rs("Lrr") = userid
rs("lrsj") = Now()
rs("spleader") = "无需审批"
rs("spec") = spec
rs("spec_no") = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now())
rs("status") = 1
rs("uptype") = "doc"
rs("zdy1") = 4
rs.Update
End If
rs.Close
stm.Close
fso.DeleteFile SaveFileName
End If
conn.Close
errorhandle:
oWordApp.Quit
Set stm = Nothing
Set fso = Nothing
Set oWordDoc = Nothing
Set oWordApp = Nothing
End Function
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
var intRowIndex=0;
var intCellIndex=0;
function insertRow(RowIndex){
var objRow=myTable.insertRow(RowIndex);
var objCell0=objRow.insertCell(0);
var objCell1=objRow.insertCell(1);
objCell0.innerText=document.myForm.Cell0.value;
objCell1.innerText=document.myForm.Cell1.options[document.myForm.Cell1.selectedIndex].value;
objRow.style.background="green";
}
function delRow(RowIndex){
myTable.deleteRow(RowIndex);
}
function insertCell(cellIndex){
var objCell=myTable.rows[intRowIndex].insertCell(cellIndex);
objCell.innerText=document.myForm.Cell2.value;
objCell.style.background="pink";
}
function delCell(cellIndex){
myTable.rows[intRowIndex].deleteCell(cellIndex);
}
function getIndex(){
intRowIndex=event.srcElement.parentElement.rowIndex;
intCellIndex=event.srcElement.cellIndex;
pos.innerText="第"+(intRowIndex+1)+"行"+"第"+(intCellIndex+1)+"列";
}
function pSelect(){
var objSelect=document.myForm.Cell1;
if (objSelect.options[0].selected){
alert("请选择性别");
}
}
</script>
</head>
<body onload="pos.innerText='第'+(intRowIndex+1)+'行'+'第'+(intCellIndex+1)+'列'">
<center>
现在的位置:<br>
<div id="pos"></div>
<br>
<table id="myTable" border="1" style="WIDTH: 282px; HEIGHT: 224px">
<tr onclick="getIndex()">
<td>姓名</td>
<td>性别</td>
</tr>
<tr onclick="getIndex()">
<td>徐祥</td>
<td>男</td>
</tr>
<tr onclick="getIndex()">
<td>应波</td>
<td>女</td>
</tr>
<tr onclick="getIndex()">
<td>童佩峰</td>
<td>女</td>
</tr>
</table>
<form name="myForm">
<input type="text" name="Cell0" value="请输入姓名">
<select name="Cell1" value="请输入性别">
<option selected>请选择性别</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
<input type="text" name="Cell2" value="请输入"><br>
<input type="button" value="插入行" onclick="insertRow(intRowIndex),pSelect()"> <input type="button" value="添加行" onclick="insertRow(myTable.rows.length),pSelect()">
<input type="button" value="删除行" onclick="delRow(intRowIndex)"> <input type="button" value="插入列" onclick="insertCell(intCellIndex)">
<input type="button" value="添加列" onclick="insertCell(myTable.rows[intRowIndex].cells.length)">
<input type="button" value="删除列" onclick="delCell(intCellIndex)"><br>
<input type="button" value="左对齐" onclick=" myTable.rows[intRowIndex].align='left'">
<input type="button" value="居中对齐" onclick=" myTable.rows[intRowIndex].align='center'">
<input type="button" value="右对齐" onclick=" myTable.rows[intRowIndex].align='right'">
<input type="button" value="上对齐" onclick=" myTable.rows[intRowIndex].vAlign='top'">
<input type="button" value="中对齐" onclick=" myTable.rows[intRowIndex].vAlign='middle'">
<input type="button" value="下对齐" onclick=" myTable.rows[intRowIndex].vAlign='bottom'">
</form>
</center>
</body>
</html>