首页 > 解决方案 > 以以下方式创建 SharePoint 列表到 CSV 报告

问题描述

以下面显示的方式将 SharePoint 列表转换为 CSV 报告创建中的任何潜在客户

标签: csvsharepoint

解决方案


我们可以使用下面的 PowerShell 来实现它。

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web
$web = Get-SPWeb -identity "http://sp2013/sites/team"

#Get the Target List
$list = $web.Lists["TestExportToCSV"]

#Array to Hold Result - PSObjects
$ListItemCollection = @()

#Get All List items
$listItems=$list.Items
foreach($item in $listItems) {
    $ExportItem = New-Object PSObject 
    $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $item["Title"]
    $ExportItem | Add-Member -MemberType NoteProperty -Name "City" -value $item["City1"]
    $ExportItem | Add-Member -MemberType NoteProperty -Name "State" -value $item["State1"]
    $ExportItem1 = New-Object PSObject 
    $ExportItem1 | Add-Member -MemberType NoteProperty -name "Title" -value $item["Title"]
    $ExportItem1 | Add-Member -MemberType NoteProperty -Name "City" -value $item["City2"]
    $ExportItem1 | Add-Member -MemberType NoteProperty -Name "State" -value $item["State2"]

    #Add the object with property to an Array
    $ListItemCollection += $ExportItem
    $ListItemCollection += $ExportItem1
}
#Export the result Array to CSV file
$ListItemCollection | Export-CSV "c:\ListData.csv" -NoTypeInformation                       

#Dispose the web Object
$web.Dispose()

在此处输入图像描述


推荐阅读