媽的,研究了一個晚上,終於搞定了。
代碼如下:
'開始別忘了導入這兩個東東
'導入Word類庫
Imports Microsoft.Office.Core
Imports Word
Public Class Form1
'提取過程
Sub FuckWord()
'定義Word程序
Dim oWordApplic As Word.Application = New Word.Application
'定義文檔
Dim oDocument As Word.Document
'定義區域
'Dim oRange As Word.Range
'定義文件路徑
Dim WordFilePath As String = "D:\客觀題.doc"
'默認的參數
Dim isReadOnly As Boolean = False '只讀
Dim isVisible As Boolean = True '程序是否可見
Dim missing = System.Reflection.Missing.Value
'打開Word文檔
oDocument = oWordApplic.Documents.Open(WordFilePath, missing, isReadOnly, missing, missing, missing, missing, missing, missing, missing, missing, isVisible, missing, missing, missing, missing)
'激活程序
oDocument.Activate()
'此處我選擇特定的表格列,起始編號不是0,而是1
oDocument.Tables(1).Cell(6, 2).Select()
'這句是把邊框去掉,方法就是少選一個最後的回車符。
oDocument.Range(oWordApplic.Selection.Range.Start, oWordApplic.Selection.Range.End - 1).Select()
'複製選擇內容
oWordApplic.Selection.Copy()
'粘貼內容
Me.RichTextBox1.Paste()
'遍歷每個InlineShapes
For Each Il As InlineShape In oRange.InlineShapes
If Il.Type = WdInlineShapeType.wdInlineShapePicture Then '判斷類型(共11種類型 類型說明見後)
Il.Select() '先選擇(很重要,必須的步驟)
oWordApplic.Selection.CopyAsPicture() '選擇拷貝至剪貼板
Me.PictureBox1.Image = My.Computer.Clipboard.GetImage '從剪貼板獲取
End If
Next
'關閉當前文檔
oDocument.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
'關閉所有文檔
'oWordApplic.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
'退出程序
oWordApplic.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordApplic)
oWordApplic = Nothing
'wdInlineShapeEmbeddedOLEObject 嵌入式OLE對象
'wdInlineShapeHorizontalLine 水平線
'wdInlineShapeLinkedOLEObject 鏈接式OLE對象
'wdInlineShapeLinkedPicture 鏈接式圖片
'wdInlineShapeLinkedPictureHorizontalLine(不知道什麼鬼玩意)
'wdInlineShapeOLEControlObject OLE控制對象
'wdInlineShapeOWSAnchor OWS錨點
'wdInlineShapePicture 嵌入式圖片
'wdInlineShapePictureBullet 圖片佔位符
'wdInlineShapePictureHorizontalLine (不知道什麼鬼玩意)
'wdInlineShapeScriptAnchor (不知道什麼鬼玩意)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call FuckWord()
End Sub