Skip to content

Instantly share code, notes, and snippets.

@pkskelly
Created July 3, 2017 18:11
Show Gist options
  • Save pkskelly/5e904d38565016b3978c223c9c17d754 to your computer and use it in GitHub Desktop.
Save pkskelly/5e904d38565016b3978c223c9c17d754 to your computer and use it in GitHub Desktop.
Simple Script to combine all SMAT CSV files into a single file
$csvFiles = Get-ChildItem $PSScriptRoot -Include *.csv -Recurse
$fileCount = $csvFiles.Count
Write-Host "Processing files: ($fileCount)"
foreach ($csv in $csvFiles) {
Write-Host "Processing $($csv.BaseName)..."
}
$outputfilename = read-host "Please enter the output file name"
Write-Host Creating: $outputfilename
$excelapp = new-object -comobject Excel.Application
$excelapp.Visible = $true
$excelapp.DisplayAlerts = $false
$destWorkbook = $excelapp.Workbooks.Add()
$sheet = 1
foreach ($csv in $csvFiles) {
Write-Host "Processing $($csv.BaseName)..."
$sourceWorkbook = $excelapp.Workbooks.Open($csv)
$sourceWorkbook.Sheets.Item(1).Copy($destWorkbook.Sheets.Item($sheet))
$sourceWorkbook.Close()
$sheet++
}
$destWorkbook.SaveAs("$($PSScriptRoot)\$outputfilename")
$destWorkbook.Close()
$excelapp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment