Created
July 3, 2017 18:11
-
-
Save pkskelly/5e904d38565016b3978c223c9c17d754 to your computer and use it in GitHub Desktop.
Simple Script to combine all SMAT CSV files into a single file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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