以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  为何不能执行目录检测?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=154620)

--  作者:明天的灵
--  发布时间:2020/9/20 23:11:00
--  为何不能执行目录检测?
想学习读取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

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:读取word表格.table



--  作者:有点蓝
--  发布时间:2020/9/21 8:34:00
--  
我测试没有问题。

卸载重新安装一下office,需要安装完整版的,最好是32位版本。不能安装精简版、绿色版的。一般Ghost系统自带的都是精简版

--  作者:明天的灵
--  发布时间:2020/9/21 9:45:00
--  
是其他原因(测试的word文档表格不对)