0

我想通过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
4

2 回答 2

2

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

您可以使用带有 C# 或 VB.Net 的 openXML 来实现这一点。

希望这可以帮助。

于 2012-09-10T07:13:41.490 回答
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
于 2012-09-10T07:34:36.043 回答