Search This Blog

Showing posts with label import. Show all posts
Showing posts with label import. Show all posts

Tuesday, March 04, 2025

Import multiple CSV files into separate Excel worksheets

 #import multiple CSV files into separate Excel worksheets
$wrkfldr='C:\temp'

$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$wb = $excel.Workbooks.Add()

Get-ChildItem $wrkfldr\*.csv | ForEach-Object {
    if ((Import-Csv $_.FullName).Length -gt 0) {
        $csvBook = $excel.Workbooks.Open($_.FullName)
        $csvBook.ActiveSheet.Copy($wb.Worksheets($wb.Worksheets.Count))
        $csvBook.Close()
    }
}