我想将word文档的所有图像存储在sql数据库中。我找到了几个关于如何通过InlineShapes
集合解析图像的代码示例,它们工作正常。但是,我现在错过了一个关于如何将图像存储在sql server image列中的示例。
任何人都可以发布一个示例,它将InlineShape
对象存储在数据库中。是使用command
还是recordset
对象?
更新:这是代码
Sub SavePictures()
Dim SQL As String
Dim RS As ADODB.Recordset
Dim cnBon As ADODB.Connection
Dim intCount As Integer
Dim i As Integer
SQL = "Select [ID] ,[Datei] ,[Seite] ,[Bild] from Bilder Where 1=0"
strConn = "working Connection string"
Set cnBon = New ADODB.Connection
cnBon.Open strConn
Set RS = CreateObject("ADODB.Recordset")
RS.Open SQL, cnBon, adOpenKeyset, adLockOptimistic, adCmdText
For i = 1 To InlineShapes.Count
If InlineShapes.Item(i).Type = wdInlineShapePicture Then
RS.AddNew
RS("Datei") = ActiveDocument.Name
RS("Seite") = i
'This is where I'm stuck. How do I Access the Picture to save it in the Recordset?
RS("Bild") = InlineShapes.Item(i)
RS.Update
End If
Next i
RS.Close
cnBon.Close
Set RS = Nothing
Set cbbon = Nothing
End Sub
答案 0 :(得分:0)
这是工作代码
Sub SavePictures()
Dim SQL As String
Dim RS As ADODB.Recordset
Dim cnBon As ADODB.Connection
Dim intCount As Integer
Dim i As Integer
SQL = "Select [ID] ,[Datei] ,[Seite] ,[Bild] from Bilder Where 1=0"
strConn = "working Connection string"
Set cnBon = New ADODB.Connection
cnBon.Open strConn
Set RS = CreateObject("ADODB.Recordset")
RS.Open SQL, cnBon, adOpenKeyset, adLockOptimistic, adCmdText
For i = 1 To InlineShapes.Count
If InlineShapes.Item(i).Type = wdInlineShapePicture Then
RS.AddNew
RS("Datei") = ActiveDocument.Name
RS("Seite") = i
'This is where I'm stuck. How do I Access the Picture to save it in the Recordset?
RS("Bild") = InlineShapes.Item(i).Range.EnhMetaFileBits
RS.Update
End If
Next i
RS.Close
cnBon.Close
Set RS = Nothing
Set cbbon = Nothing
End Sub