Alan's Blog

"Yeah. I wrote a script that will do that."

Menu
  • About My Blog
Menu

Combine CSV Files to XLSX File with Worksheets

Posted on February 4, 2017 by Alan

Three years ago, I posted CombineXLSheets.vbs, a vbScript which allows you to drop and drag Excel spreadsheets onto it and have them combined into a single workbook file with multiple worksheets.  Now that I am working in PowerShell, I have found the need to consolidate CSV files.  Parts of  Combine-CSVFilesToWorksheets.ps1 come from code ported from the vbscript, and this script does a similar job.

I have been experimenting with input validation choices, and you can see some of it here.  One of the things I learned is that a single parameter can have more than one script validations using ValidateScript.  I also decide that the error handling for this is pretty ugly, and moved other input validation into the body of the script.

The script requires that you specify the folder with the CSV files, and the output file for the combined data.  By default the worksheets are named with the base name of the CSV file, and autofit is applied to the columns.  You may optionally turn off autofit, and can delete all of the CSV files when done or the CSV folder itself.  Because this is an advanced function, you can use Get-Help for full help.  The script also supports ShouldProcess (-WhatIf ).

This script requires Excel.

Script Text

Leave a Reply

You must be logged in to post a comment.

Search

Please Note

All the scripts are saved as .txt files. Newer files have a “View Script” button which will let you save or open a script in notepad. For earlier posts, the easiest way to download with IE is to right click on the link and use “Save Target As”. Rename file from Name_ext.txt to Name.ext.

To see a full post after searching, please click on the title.

PowerShell Scripts were written with version 3 or later.

https connections are supported.

All new users accounts must be approved, as are comments. Please be patient.  If you find a post error or a script which doesn’t work as expected, I appreciate being notified.  My email is my first name at the domain name, and you are welcome to contact me that way.

Tags

1E ACLS Active Directory ActiveDirectory ADSI Advanced Functions Audit Change Administrator Password COMObject Computer Groups DateTime Desktop DNS Excel FileScriptingObject Forms General GPO GPS Group Policy Hacks ISE Lockout logons NAV740 Nessus OU OU permissions Outlook Pick Folder Power PowerShell Powershell Scriptlets RDP SCCM schedule reboot Scripting Security Shell.Application user information VBA Windows Update WMI WordPress WPF

Categories

akaplan.com

  • Back to Home Page

Archives

Scripting Sites

  • A Big Pile of Small Things
  • Adam, the Automator
  • Art of the DBA
  • Ashley McGlone
  • Boe Prox
  • Carlo Mancini
  • DexterPOSH
  • Doug Finke
  • Jaap Brasser's Blog
  • JeffOps The Scripting Dutchman
  • Jonathan Medd's Blog
  • Keith Hill's Blog
  • LazyWinAdmin
  • Nana Lakshmanan
  • PowerShell Magazine
  • PowerShell Team Blog
  • PowerShell.org
  • PwrShell.net
  • Richard Siddaway's Blog
  • Ryan Yates' Blog
  • Skatterbrainz
  • The Lonely Administrator

SQL Site

  • Art of the DBA

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2025 Alan's Blog | Theme by SuperbThemes

Terms and Conditions - Privacy Policy