通过以下方式将SharePoint列表转换为CSV报告创建

时间:2018-08-02 10:26:27

标签: csv sharepoint

以下面显示的方式将SharePoint列表转换为CSV报表创建的任何线索

1 个答案:

答案 0 :(得分:0)

我们可以使用下面的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()

enter image description here