Foxtable(狐表)用户栏目专家坐堂 → WORD导入表代码修改


  共有1360人关注过本帖树形打印复制链接

主题:WORD导入表代码修改

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/7/6 23:38:00 [显示全部帖子]

如果你的word文件没有表格,那么使用doc.tables(1)获取就会报错。

 

你可以判断表格个数 if doc.tables.count >= 1 then

 

For Each AAA As String In filesys .GetFiles("d:\lzxx1")
    Dim app As New MSWord.Application
    try
        Dim fileName = AAA
        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)
        Dim nr As Row = Tables("表A").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
    catch ex As exception
        'msgbox(ex.message)
    finally
        app.Quit
    End try
Next


 回到顶部