RamblingCookieMonster/PSExcel

new example

hasafi opened this issue · 1 comments

hi, I create some small script which can be useful for others.

content of file csv2xlsx.ps1:

function csv2xlsx {
Param(
[Parameter(Mandatory=$false,ValueFromPipeline=$true)]
[ValidateScript({Test-Path $_})]
[String]$CSVfile
)

Process {
if(-not($CSVfile)) { Throw "You must supply a value for -CSVfile" }

Import-Module PSExcel

$path = split-path $CSVfile -Parent
$file = split-path $CSVfile -Leaf

$infile = join-path $path $file
$outfile = join-path $path ($file.split('.')[-2]+".xlsx")

$CSV = Import-Csv $infile
$CSV | Export-XLSX -Path $outfile

$Excel = New-Excel -Path $outfile
$Worksheet = $Excel | Get-Worksheet
$Worksheet | Format-Cell -Autofit -StartColumn 1 -EndColumn 100
$Worksheet | Format-Cell -AutoFilter $True
$Excel | Close-Excel -Save
$outfile
}
}

csv2xlsx $args[0]

Thanks!

Closing this out, but it will remain available for other folks - cheers!