如何使用 Excel VBA 将项目添加到 Sharepoint 列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10147731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add items to a Sharepoint list using Excel VBA?
提问by sigil
I have an Excel-based application that gathers some user input, and makes some calculations based on that user input. The application itself doesn't store any of the user input or calculations; currently whenever a user runs the application, it sends the data to an Access database and inserts a row into an Access table xlTable
that's linked to a Sharepoint list. The relevant code is:
我有一个基于 Excel 的应用程序,它收集一些用户输入,并根据该用户输入进行一些计算。应用程序本身不存储任何用户输入或计算;当前,每当用户运行该应用程序时,它都会将数据发送到 Access 数据库,并xlTable
在链接到 Sharepoint 列表的 Access 表中插入一行。相关代码是:
sub sendToSharepoint(userName as string, folderPath as string, calculatedValue as long)
dim db as DAO.database
dim insertStr as string
'open connection to Access db
set db=OpenDatabase(myDatabasePath)
'build insert string
insertStr="insert into xlTable (userName,folderPath,calculatedValue,workDate) values (""" & userName & """,""" & folderPath & """," & calculatedValue & ","#" & Now & "#)"
'insert values into xlTable, which adds them to the Sharepoint list
db.execute insertStr,dbFailonError
end sub
Because we've had some issues with Access disconnecting from Sharepoint and therefore not populating the list, and in general want to simplify our data transfer process, I'd like to send the data directly from Excel to Sharepoint without using Access. I've read some stuff on SO about using Web Services to update Sharepoint, but I haven't been able to figure out how these work exactly, or how to implement them in VBA.
因为我们在 Access 与 Sharepoint 断开连接时遇到了一些问题,因此无法填充列表,并且通常希望简化我们的数据传输过程,所以我想不使用 Access 直接将数据从 Excel 发送到 Sharepoint。我已经阅读了一些关于使用 Web 服务更新 Sharepoint 的内容,但我一直无法弄清楚这些是如何工作的,或者如何在 VBA 中实现它们。
What info would I need about my Sharepoint list to manipulate it from Excel VBA similar to the above code? Do I need to add any references?
我需要关于我的 Sharepoint 列表的哪些信息才能从类似于上述代码的 Excel VBA 操作它?我需要添加任何参考吗?
采纳答案by naivists
All data manipulations can be done through SharePoint Lists Web servicenamed lists.asmx
. You have to call into that web sevice. For instance UpdateListItems
methodshould do what MS Access does now.
所有数据操作都可以通过名为.SharePoint列表的 Web 服务完成lists.asmx
。您必须调用该 Web 服务。例如UpdateListItems
方法应该做 MS Access 现在做的事情。
One option you can use to access the lists web sevice, is "Microsoft SOAP Toolkit" which has to be installed as office component (never done that, but here is an article describing it: http://oreilly.com/pub/h/1306
您可以用来访问列表网络服务的一个选项是“Microsoft SOAP Toolkit”,它必须作为办公组件安装(从未安装过,但这里有一篇文章描述它:http: //oreilly.com/pub/h /1306
Another option is to use MSXML library (which is always available) and sending SOAP requests as simple HTTP requests. Then parsing the results as xml. There is an article showing examples how to do it: http://blogs.msdn.com/b/jpsanders/archive/2007/06/14/how-to-send-soap-call-using-msxml-replace-stk.aspx
另一种选择是使用 MSXML 库(始终可用)并将 SOAP 请求作为简单的 HTTP 请求发送。然后将结果解析为xml。有一篇文章展示了如何做到这一点:http: //blogs.msdn.com/b/jpsanders/archive/2007/06/14/how-to-send-soap-call-using-msxml-replace-stk .aspx
回答by Ulf
You could use the Camelot .NET Connector to query SharePoint directly from VB/ASP using the COM+ component that comes with the next version (2.0). See http://bendsoft.com/net-sharepoint-connector/.
您可以使用 Camelot .NET 连接器使用下一版本 (2.0) 附带的 COM+ 组件直接从 VB/ASP 查询 SharePoint。请参阅http://bendsoft.com/net-sharepoint-connector/。
'define connection string
Dim connectionString
connectionString = "Server=mysharepointserver.com;Database=sites/test;Domain=;User=xxxx;Password=xxxx;Authentication=Ntlm;TimeOut=50;RecursiveMode=RecursiveAll;DecodeName=True;NoListFilters=False;ExpandUserFields=False;StrictMode=true;DefaultLimit=1000"
'activate connector com+
Dim connector
Set Connector = CreateObject("Camelot.SharePointConnector.Com.Connector")
' your query
Dim sql
sql = "insert into sharepointlist (userName, folderPath, calculatedValue, workDate) values ('" & userName & "', '" & folderPath & "', " & calculatedValue & ", '" & Now & "')"
' execute query
connector.ExecuteNonQuery(sql, connectionString)