无法将记录从 Excel 插入到 SharePoint
Can't insert records from Excel to SharePoint
目前我遇到了 Excel ADO 问题。
事情是这样的
我试图插入一些记录
从 "Excel table" 到 "SharePoint list" 使用 ADO 连接。
但失败了(无法识别 Excel table in SQL 语句)
Dim SQL As String
Dim CN As New ADODB.Connection
Dim OLEDB As String
Dim LIST As String
Dim SITE As String
LIST = "{EE028282-3D7E-4D37-93EE-50FB69C4432C}"
SITE = "https://asml.sharepoint.com/teams/FFKR_DUV_YS_Installation_and_Relocation/Product"
OLEDB = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=" & SITE & ";" & _
"LIST=" & LIST & ";"
Set CN = New ADODB.Connection
CN.Open OLEDB
SQL = SQL & "INSERT INTO Schedule_DB (NAME,TYPE_W) "
SQL = SQL & "SELECT * "
SQL = SQL & "FROM [" & ThisWorkbook.FullName & "].[S_RAW$] "
CN.Execute CommandText:=SQL
CN.Close
如果我 运行 它我得到错误 ->
Error image
我已经检查过错别字,项目数量太多,所以我宁愿把它作为一个SQL语句来处理。
"Excel to Excel" 效果很好但对 "Excel to SharePoint List" 仍然没有想法。
请分享您的建议。
当您想从 Excel sheet 中读取数据时,您需要有一个具有 读取权限 的 ADODB.Connection
,然后才能写入数据到您的 SharePoint 列表,您需要另一个 ADODB.Connection
具有 写入权限 。
Note: You can't transport your whole data in that way, You can generate a big command with whole data then use it or generate command for each record of your Excel data.
关于您的异常,它只是说它无法在 SharePoint 列表中找到您的 sheet 姓名。
指导您的示例可以是这样的:
Dim cnnXl As New ADODB.Connection
Dim rsXl As New ADODB.Recordset
Dim cnnShP As New ADODB.Connection
conStrXl = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\yourExcel.xlsx';" & _
"Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;"";"
commandXl = "SELECT [Field1], [Field2] FROM [Worksheet$$A1:D7] WHERE [Thing1] > 1"
conStrShP = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=yourSite;LIST={yourListCLSID};"
然后打开cnnXl
和运行commandXl
读取数据到rsXl
.
然后打开 cnnShP
并遍历 rsXl
记录并创建你的 commandShP
并执行它。
目前我遇到了 Excel ADO 问题。
事情是这样的 我试图插入一些记录 从 "Excel table" 到 "SharePoint list" 使用 ADO 连接。 但失败了(无法识别 Excel table in SQL 语句)
Dim SQL As String
Dim CN As New ADODB.Connection
Dim OLEDB As String
Dim LIST As String
Dim SITE As String
LIST = "{EE028282-3D7E-4D37-93EE-50FB69C4432C}"
SITE = "https://asml.sharepoint.com/teams/FFKR_DUV_YS_Installation_and_Relocation/Product"
OLEDB = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=" & SITE & ";" & _
"LIST=" & LIST & ";"
Set CN = New ADODB.Connection
CN.Open OLEDB
SQL = SQL & "INSERT INTO Schedule_DB (NAME,TYPE_W) "
SQL = SQL & "SELECT * "
SQL = SQL & "FROM [" & ThisWorkbook.FullName & "].[S_RAW$] "
CN.Execute CommandText:=SQL
CN.Close
如果我 运行 它我得到错误 ->
Error image
我已经检查过错别字,项目数量太多,所以我宁愿把它作为一个SQL语句来处理。
"Excel to Excel" 效果很好但对 "Excel to SharePoint List" 仍然没有想法。
请分享您的建议。
当您想从 Excel sheet 中读取数据时,您需要有一个具有 读取权限 的 ADODB.Connection
,然后才能写入数据到您的 SharePoint 列表,您需要另一个 ADODB.Connection
具有 写入权限 。
Note: You can't transport your whole data in that way, You can generate a big command with whole data then use it or generate command for each record of your Excel data.
关于您的异常,它只是说它无法在 SharePoint 列表中找到您的 sheet 姓名。
指导您的示例可以是这样的:
Dim cnnXl As New ADODB.Connection
Dim rsXl As New ADODB.Recordset
Dim cnnShP As New ADODB.Connection
conStrXl = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\yourExcel.xlsx';" & _
"Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;"";"
commandXl = "SELECT [Field1], [Field2] FROM [Worksheet$$A1:D7] WHERE [Thing1] > 1"
conStrShP = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=yourSite;LIST={yourListCLSID};"
然后打开cnnXl
和运行commandXl
读取数据到rsXl
.
然后打开 cnnShP
并遍历 rsXl
记录并创建你的 commandShP
并执行它。