0

I have written the power shell script to export the view in to a CSV file. But I want the same data to be exported to EXCel. I don't have excel installed on my share point server and my client does not allow to install on the server.

The Excel should be in the below format with color formatting.Any help on this is appreciated.

I tried with Office Interop but still no luck. It gives Com application Error.

Power shell Code:

 Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null 
    $site = new-object Microsoft.SharePoint.SPSite("http://mytest.services.com")
    $web = $site.RootWeb
    $list = $web.Lists["MyCustomList"]
    $view = $list.Views["MyView"] 
    $items = $list.GetItems($view)   
    $items | %{ select-object -input $_ -prop @{Name='ID';expression={$_.ID;}}, @{Name='Issue ID';expression={$_["Issue ID"];}},@{Name='Title';expression={$_.Title;}},@{Name='Issue Type';expression={$_["Issue Type"];}},@{Name='Priority';expression={$_["Priority"];}},@{Name='Issue Status';expression={$_["Issue Status"];}},@{Name='Assigned To';expression={$userfield=New-Object Microsoft.SharePoint.SPFieldUserValue($web,$_["Assigned To"]);$userfield.User.DisplayName;}},@{Name='Reported On';expression={$_["Reported On"];}},@{Name='Reported By';expression={$_["Reported By"];}},@{Name='Description';expression={[Microsoft.SharePoint.Utilities.SPHttpUtility]::ConvertSimpleHtmlToText($_["Description"],-1) -replace '\s+', ' ';}},@{Name='Comments';expression={[Microsoft.SharePoint.Utilities.SPHttpUtility]::ConvertSimpleHtmlToText($_["Comments"],-1) -replace '\s+', ' ';}},@{Name='Resolution Notes';expression={[Microsoft.SharePoint.Utilities.SPHttpUtility]::ConvertSimpleHtmlToText($_["Resolution Notes"],-1) -replace '\s+', ' ';}},@{Name='Date Closed';expression={$_["Date Closed"];}};} | Export-Csv -Path "D:\Test\MyView $(get-date -f MM-dd-yyyy).csv" -NoType 

Out Format of Excel should be like this with Color formatting. enter image description here

  • pretty sure this wont be possible without third party software, and if you install any then you can also just install excel – Paul Nov 10 '14 at 14:53
  • Try [this](https://gallery.technet.microsoft.com/office/Export-XLSX-PowerShell-f2f0c035). I'm not sure if it does any formatting (probably not) but it's a good place to start anyway. – Alexander Obersht Nov 10 '14 at 16:09
  • You should try EPPlus. Have a look at my answer here [powershell excel access without installing Excel](http://stackoverflow.com/questions/20011481/powershell-excel-access-without-installing-excel/27710299#27710299). – Florian Feldhaus Jan 31 '15 at 19:47

0 Answers0