想学习读取WORD文件的内容,搜索到论坛已有相关资料,按http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=71352
这个话题的第4楼代码去操作,却不能执行目录检测命令,具体代码如下:
(执行到输出1后就出错:未指定的错误 (Exception from HRESULT: 0x80004005 (E_FAIL)))
测试环境为FT2020试用版
Dim dlg As new OpenFileDialog
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
Dim app As New MSWord.Application
try
MessageBox.Show("1")
If FileSys.DirectoryExists(ProjectPath & "Attachments") = False Then
MessageBox.Show("2")
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