![](/img/trans.png)
[英]How to read the fill pattern in Excel using Microsoft.Office.Interop
[英].NET read word/excel documents without Microsoft.Office.Interop
我正在嘗試在VB.NET下打開一個doc文件,我找到了一個非常簡單的方法來使用word:
例如:
Dim doc As Word.Document
Dim wordApp As New Word.Application
Dim allText As String
Try
doc = wordApp.Documents.Open("C:\marti.doc")
allText = doc.Range.Text()
doc.Close()
RichTextBox1.Text = allText
Catch
'error
End Try
(更多詳細信息: http : //support.microsoft.com/kb/316383 )
這可能有效,但需要打開Microsoft Word窗口來處理它。 我需要在沒有安裝Word的情況下使用它。 所以我需要一個可以打開doc / excel文件的庫。
你知道一個好的圖書館可以做到這一點嗎?
我找到了這個庫: http : //bytescout.com/download/trial/documentsdk.html
你試過這個嗎?
與Office文件交互的推薦方法是通過Office OpenXML庫。 你可以在這里得到它。
如果您使用的是Microsoft Office 2003,則可以在Open XML中加載和保存文檔(如果已安裝Word,Excel和PowerPoint 2007文件格式的Microsoft Office兼容包)。 您可以下載兼容包並在此處查找更多信息。
這是收集文檔內容的示例方法:
Private Shared Function GetWordDocContent(strDoc As String) As String
Dim stream As Stream = File.Open(strDoc, FileMode.Open)
Dim wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(stream, True)
Dim body As Body = wordprocessingDocument__1.MainDocumentPart.Document.Body
Dim content As String = body.InnerText
wordprocessingDocument__1.Close()
Return content
End Function
另一個例子在這里 。
對於舊的單詞格式(.doc)我嘗試過Syncfusion DocIO組件,但我更喜歡使用NetOffice的自動化,比互操作更好
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.