Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
mark word读取图片
Dim app As New MSWord.Application
try
Dim fileName = "C:\Documents and Settings\Administrator\My Documents\下载\从word取数据\从WORD取数据\黄某某.doc"
Dim doc = app.Documents.Open(fileName)
app.ActiveWindow.Selection.WholeStory
For Each shape As object In app.ActiveWindow.Selection.InlineShapes
If shape.Type = MSWord.WdInlineShapeType.wdInlineShapePicture
Dim img As Byte() = shape.Range.EnhMetaFileBits
Dim bmp As new Bitmap(new IO.MemoryStream(img))
bmp.Save("d:\test.jpg")
End If
Next
catch ex As exception
msgbox(ex.message)
finally
app.Quit
End try
读取某个单元格的值,参考
Dim app As New MSWord.Application
try
Dim fileName = "C:\Documents and Settings\Administrator\My Documents\下载\从word取数据\从WORD取数据\黄某某.doc"
Dim doc = app.Documents.Open(fileName)
Dim t = doc.Tables(1)
Dim text = t.Cell(1, 2).Range.Text.ToString()
text = text.Substring(0, text.Length - 2)
msgbox(text)
catch ex As exception
msgbox(ex.message)
finally
app.Quit
End try
按钮代码
Dim dlg As new OpenFileDialog
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
Dim app As New MSWord.Application
try
If FileSys.DirectoryExists(ProjectPath & "Attachments") = False Then
FileSys.CreateDirectory(ProjectPath & "Attachments/")
End If
For Each filename As String In dlg.FileNames
Dim doc = app.Documents.Open(fileName)
Dim nr As Row = Tables("个人信息表").AddNew
Dim t = doc.Tables(1)
Dim text = t.Cell(1, 2).Range.Text.ToString()
text = text.Substring(0, text.Length - 2)
nr("姓名") = text
'-------------
app.ActiveWindow.Selection.WholeStory
For Each shape As object In app.ActiveWindow.Selection.InlineShapes
If shape.Type = MSWord.WdInlineShapeType.wdInlineShapePicture
Dim img As Byte() = shape.Range.EnhMetaFileBits
Dim bmp As new Bitmap(new IO.MemoryStream(img))
bmp.Save(ProjectPath & "Attachments/" & nr("姓名") & ".jpg")
End If
Next
nr("相片") = nr("姓名") & ".jpg"
Doc.Close
Next
catch ex As exception
msgbox(ex.message)
finally
app.Quit
End try
End If