Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图书列表-使用Excel VBA条形码查找从amazon获取图书详细信息_Vba_Excel_Amazon Web Services_Barcode - Fatal编程技术网

图书列表-使用Excel VBA条形码查找从amazon获取图书详细信息

图书列表-使用Excel VBA条形码查找从amazon获取图书详细信息,vba,excel,amazon-web-services,barcode,Vba,Excel,Amazon Web Services,Barcode,我有一个条形码阅读器和一堆书。对于每本书,我想在Excel电子表格中列出书名和作者 我的观点是,一些VBA代码连接到Amazon web服务会使这变得更容易 我的问题是——以前没有人这样做过吗?你能给我举个最好的例子吗 如果条形码是ISBN,这似乎很可能,也许你可以使用:amazon.com/Advanced Search Books/b?ie=UTF8&node=241582011 事实上,我找不到一个基于VBA ISBN的程序从网上获取图书数据,所以我决定做一个 下面是一个VBA宏,它使用来

我有一个条形码阅读器和一堆书。对于每本书,我想在Excel电子表格中列出书名和作者

我的观点是,一些VBA代码连接到Amazon web服务会使这变得更容易


我的问题是——以前没有人这样做过吗?你能给我举个最好的例子吗

如果条形码是ISBN,这似乎很可能,也许你可以使用:amazon.com/Advanced Search Books/b?ie=UTF8&node=241582011

事实上,我找不到一个基于VBA ISBN的程序从网上获取图书数据,所以我决定做一个

下面是一个VBA宏,它使用来自的服务。例子。这些服务是免费的,不需要身份验证

要运行它,您应该在“工具->参考”(在VBE窗口中)检查“MicrosoftXML6.0”库

此宏从当前单元格中获取ISBN(10位数字),并用作者和标题填充以下两列。您应该能够轻松地循环浏览完整的列

代码已经过测试(嗯,有一点),但是没有错误检查

 Sub xmlbook()
 Dim xmlDoc As DOMDocument60
 Dim xWords As IXMLDOMNode
 Dim xType As IXMLDOMNode
 Dim xword As IXMLDOMNodeList
 Dim xWordChild As IXMLDOMNode
 Dim oAttributes As IXMLDOMNamedNodeMap
 Dim oTitle As IXMLDOMNode
 Dim oAuthor As IXMLDOMNode
 Set xmlDoc = New DOMDocument60
 Set xWords = New DOMDocument60
 xmlDoc.async = False
 xmlDoc.validateOnParse = False
 r = CStr(ActiveCell.Value)

 xmlDoc.Load ("http://xisbn.worldcat.org/webservices/xid/isbn/" _
              + r + "?method=getMetadata&format=xml&fl=author,title")

 Set xWords = xmlDoc

     For Each xType In xWords.ChildNodes
         Set xword = xType.ChildNodes
         For Each xWordChild In xword
             Set oAttributes = xWordChild.Attributes
             On Error Resume Next
             Set oTitle = oAttributes.getNamedItem("title")
             Set oAuthor = oAttributes.getNamedItem("author")
             On Error GoTo 0
         Next xWordChild
     Next xType
  ActiveCell.Offset(0, 1).Value = oTitle.Text
  ActiveCell.Offset(0, 2).Value = oAuthor.Text
 End Sub

我没有通过亚马逊,因为他们新的“直接”认证协议…

这对我有很大帮助

我已经更新了宏,允许它在一列ISBN编号中循环,直到到达一个空单元格

它还搜索出版商、年份和版本

如果某些字段不可用,我添加了一些基本的错误检查

Sub ISBN()
 Do
 Dim xmlDoc As DOMDocument60
 Dim xWords As IXMLDOMNode
 Dim xType As IXMLDOMNode
 Dim xword As IXMLDOMNodeList
 Dim xWordChild As IXMLDOMNode
 Dim oAttributes As IXMLDOMNamedNodeMap
 Dim oTitle As IXMLDOMNode
 Dim oAuthor As IXMLDOMNode
 Set xmlDoc = New DOMDocument60
 Set xWords = New DOMDocument60
 xmlDoc.async = False
 xmlDoc.validateOnParse = False
 r = CStr(ActiveCell.Value)

 xmlDoc.Load ("http://xisbn.worldcat.org/webservices/xid/isbn/" _
              + r + "?method=getMetadata&format=xml&fl=author,title,year,publisher,ed")

 Set xWords = xmlDoc

     For Each xType In xWords.ChildNodes
         Set xword = xType.ChildNodes
         For Each xWordChild In xword
             Set oAttributes = xWordChild.Attributes
             On Error Resume Next
             Set oTitle = oAttributes.getNamedItem("title")
             Set oAuthor = oAttributes.getNamedItem("author")
             Set oPublisher = oAttributes.getNamedItem("publisher")
             Set oEd = oAttributes.getNamedItem("ed")
             Set oYear = oAttributes.getNamedItem("year")
             On Error GoTo 0
         Next xWordChild
     Next xType
  On Error Resume Next
  ActiveCell.Offset(0, 1).Value = oTitle.Text

  On Error Resume Next
  ActiveCell.Offset(0, 2).Value = oAuthor.Text

  On Error Resume Next
  ActiveCell.Offset(0, 3).Value = oPublisher.Text

  On Error Resume Next
  ActiveCell.Offset(0, 4).Value = oYear.Text

  On Error Resume Next
  ActiveCell.Offset(0, 5).Value = oEd.Text


  ActiveCell.Offset(1, 0).Select
  Loop Until IsEmpty(ActiveCell.Value)

 End Sub

我只是在尝试做同样的事情时发现了这个线程。不幸的是,我在MAC电脑上,所以这些答案没有帮助。通过一点研究,我能够在MAC Excel中使用此模块:

Option Explicit

' execShell() function courtesy of Robert Knight via StackOverflow
' http://stackoverflow.com/questions/6136798/vba-shell-function-in-office-    2011-for-mac

Private Declare Function popen Lib "libc.dylib" (ByVal command As String,       ByVal mode As String) As Long
Private Declare Function pclose Lib "libc.dylib" (ByVal file As Long) As Long
Private Declare Function fread Lib "libc.dylib" (ByVal outStr As String, ByVal size As Long, ByVal items As Long, ByVal stream As Long) As Long
Private Declare Function feof Lib "libc.dylib" (ByVal file As Long) As Long

Function execShell(command As String, Optional ByRef exitCode As Long) As String
    Dim file As Long
    file = popen(command, "r")

    If file = 0 Then
        Exit Function
    End If

    While feof(file) = 0
        Dim chunk As String
        Dim read As Long
        chunk = Space(50)
        read = fread(chunk, 1, Len(chunk) - 1, file)
        If read > 0 Then
            chunk = Left$(chunk, read)
            execShell = execShell & chunk
        End If
    Wend

    exitCode = pclose(file)
End Function

Function HTTPGet(sUrl As String) As String

    Dim sCmd As String
    Dim sResult As String
    Dim lExitCode As Long
    Dim sQuery As String

    sQuery = "method=getMetadata&format=xml&fl=*"
    sCmd = "curl --get -d """ & sQuery & """" & " " & sUrl
    sCmd = "curl --get -d """ & sQuery & """" & " " & sUrl

    sResult = execShell(sCmd, lExitCode)

    ' ToDo check lExitCode

    HTTPGet = sResult

End Function

Function getISBNData(isbn As String) As String
  Dim sUrl As String
  sUrl = "http://xisbn.worldcat.org/webservices/xid/isbn/" & isbn
  getISBNData = HTTPGet(sUrl)

End Function



Function getAttributeForISBN(isbn As String, info As String) As String
  Dim data As String
  Dim start As Integer
  Dim finish As Integer


 data = getISBNData(isbn)
 start = InStr(data, info) + Len(info) + 2
 finish = InStr(start, data, """")
 getAttributeForISBN = Mid(data, start, finish - start)


End Function
这不是我所有的原创作品,我从另一个网站把它贴在一起,然后做了我自己的作品。现在,您可以执行以下操作:

getAttributeForISBN(“156882019”,“title”)

这将返回该书的标题。当然,您可以将此公式应用于A列中的所有ISBN,以查找多个标题、作者或其他内容


希望这能帮助其他人

我想OP的问题是如何将书名放入手机中。使用Excel从网页中获取信息经常被发布,因此搜索应该不难。在VBA中没有找到任何对解析HTML真正有用的东西。我用XML写了一个答案。您是否介意在回答中分享一个用于VBA中HTML解析的好指针(而不是只处理表的.qry解决方案!)?Tnx!为了将来的参考,这里是一个很好的建议,答案正是我想要的!PowerPivot非刷新功能将被阻止!;)