Hi Guys,Â
Does anyone know any way of importing data from Excel spreadsheet to an existing Sharepoint List?
Cheers.
Well, having trouble doing it.
I am getting a message
“You cannot call a method on a null-valued expression.
At C:\Users\Andre\Desktop\Additems.ps1:32 char:4
+ $spItem = $spData.AddItem()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull”
On every single record I try to add.Â
My code:Â
# Fieds to pass (Tender Enquiry No , Date, Contact Name, Contact Title, Company Name, Site Address, Status)
# Setup the correct modules for SharePoint Manipulation
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
$host.Runspace.ThreadOptions = “ReuseThread”
#Open SharePoint List
$SPServer=”https://xxxxxxx.sharepoint.com/Forms”
$SPAppList=”/Lists/Tender Enquiry form/”
$spWeb = Get-SPWeb $SPServer
$spData = $spWeb.GetList($SPAppList)
$InvFile=”SharepointEnquiries.csv”
# Get Data from Inventory CSV File
$FileExists = (Test-Path $InvFile -PathType Leaf)
if ($FileExists) {
“Loading $InvFile for processing…”
$tblData = import-csv $InvFile
} else {
“$InvFile not found – stopping import!”
exit
}
# Loop through Applications add each one to SharePoint
“Uploading data to SharePoint….”
foreach ($row in $tblData) {
“Adding entry for “+$row.”Tender Enquiry No”.ToString()
$spItem = $spData.AddItem()
$spItem[“Tender Enquiry No”] = $row.”Tender Enquiry No”.ToString()
$spItem[“Date”] = $row.”Date”.ToString()
$spItem[“Contact Name”] = $row.”Contact Name”.ToString()
$spItem[“Contact Title”] = $row.”Contact Title”.ToString()
$spItem[“Company Name”] = $row.”Company Name”.ToString()
$spItem[“Site Address”] = $row.”Site Address”.ToString()
$spItem[“Status”] = $row.”Status”.ToString()
$spItem.Update()
}
“—–“
“Upload completed”
$spWeb.Dispose()
Â