如何通过Vb.net阅读Word,Excel元数据?

时间:2012-09-10 07:05:32

标签: asp.net vb.net ms-word ms-office metadata

我想通过asp.net(vb)阅读Word,Excel文件的元数据(如作者,关键字等)。我怎么能这样做?

是否有任何样本,参考网站?

我在网上找到了以下代码,但它返回第二个语句的错误(“Dim excelbook As New Microsoft.Office.Interop.Excel.Workbook”)

Public Sub ReadExcel(ExcelFileName As String)

    Dim Wapp As New Microsoft.Office.Interop.Excel.Application
    Dim excelbook As New Microsoft.Office.Interop.Excel.Workbook

    If Wapp Is Nothing Then
        Wapp = New Microsoft.Office.Interop.Excel.Application
    End If

    If excelbook Is Nothing Then
        excelbook = New Microsoft.Office.Interop.Excel.Workbook
    Else
        excelbook.Close()
    End If

    excelbook = Wapp.Workbooks.Open(ExcelFileName)

    Dim _BuiltInProperties As Object = excelbook.BuiltinDocumentProperties

    If Not _BuiltInProperties Is Nothing Then
        excel_keyword = _BuiltInProperties("Keywords").Value
    End If

    If Not excelbook Is Nothing Then
        excelbook.Close()
    End If

    If Not Wapp Is Nothing Then
        Wapp.Quit()
    End If

End Sub

2 个答案:

答案 0 :(得分:2)

这是same的示例。或者您可以从https://dl.dropbox.com/u/79986486/StackOverFlow9684368.zip {Temporary}

下载

您可以将openXML与C#或VB.Net一起使用来实现此目的。

希望这有帮助。

答案 1 :(得分:0)

引自Social.MSDN

您可以使用DSOFile访问这些值(适用于一大堆不同的文件类型),或者更简单地说,您可以在VBA中访问这些属性

Sub Macro1()
'
' Macro1 Macro
'
    Dim mWorkbook As Workbook
    Set mWorkbook = Application.Workbooks(1)
    mWorkbook.BuiltinDocumentProperties("Author").Value = "the Author"
    mWorkbook.BuiltinDocumentProperties("Title").Value = "the Title"
    mWorkbook.BuiltinDocumentProperties("Subject").Value = "the Subject"
End Sub