【问题标题】:Transfer selected rows from excel to google spreadsheet将选定的行从 excel 传输到 google 电子表格
【发布时间】:2021-08-16 14:19:38
【问题描述】:

我有一个 Excel 电子表格,其中包含无法完全在线发布的数据。但是我需要在线检查的选定行很少。有没有办法从 excel 中提取这些行并将其发送到特定的谷歌电子表格并附加这些行? 例如,我有一个名为“公司”的列,我只想要那些针对特定公司的行说“ABC”。我需要在谷歌电子表格中在线查看“ABC”的数据。运行此脚本的人将不必手动通过电子邮件发送单独的电子表格左右。所有这些操作都应该通过单击 excel 中的链接或按钮自动进行。

【问题讨论】:

  • 我在下面给了你一个攻击计划,带回你对实施的任何具体问题。

标签: excel vba spreadsheet


【解决方案1】:

我没有正确的资源来为你组装一个工作原型,但如果我在你的位置上,我会采取这些步骤。

首先,不要在 Excel 中使用 VBA,而是使用带有 Excel Interop COM 包的完整的 VB.NET 应用程序。它的语法在很大程度上类似于 VBA 命令,但我认为在 VB.NET 中转移到 Google 文档会容易得多。

您必须使用范围对象获取所需的行。将该范围转换为数组以便于处理。

接下来,使用Google Documents List API 创建一个新的电子表格,或者提前创建一个并跳过此步骤。

使用Google Spreadsheets API 将数据移动到您的在线电子表格中。

这两个 Google API 都是 REST API,因此您必须在 VB.NET 中使用 HttpRequest 对象。 Here 是如何使用它们的一个很好的例子,只需更改 URL 以使其适合 Google。 Google 电子表格甚至提供了一个 library 来抽象出其中的许多步骤(该页面上的第二个步骤)。

【讨论】:

    【解决方案2】:
    You can send data to Google spreadsheet from Excel, you need google script & VBA code
    
    Open google spreadsheet ==> go tools ===> click script editor ==> paste below code ==> click publish ==> deploy web app ==> select "Anyone,even anonymous"
    
    [![enter image description here][1]][1]
    
    [![enter image description here][2]][2]
    
    
    function doPost(e) {
      let data = e.parameter.name
      Logger.log(data)
      SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].appendRow([data])
      return ContentService.createTextOutput("Data posted")
      
    }
    
    
    paste below code in excel VBA
    
    
    [![enter image description here][3]][3]
    
    Sub postrequestbymsxml()
        
    Dim url As String
        Dim http As Object
        
        Set http = CreateObject("MSXML2.ServerXMLHTTP")
        url = "Write here the url you get while publishing your web app"
        Data = url & "?name=EALLEN"
        http.Open "POST", Data, False
        Debug.Print
        
        http.send ("")
        
    End Sub
    
    
      [1]: https://i.stack.imgur.com/6m01N.png
      [2]: https://i.stack.imgur.com/WWfzG.png
      [3]: https://i.stack.imgur.com/VQRgF.png
    

    【讨论】:

      最近更新 更多