Convert-CsvToXlsx - Function to Convert Csv to Xlsx

This script provides the ability to convert csv files to xlsx files via the pipe line or by specifying the file. This function works by using the Excel.Application object, specifically the SaveAs method to store the file in a different format.

 
 
 
 
 
4 Star
(1)
1,102 times
Add to favorites
Office
6/11/2015
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • How can we configure through schedule task or batch file
    1 Posts | Last post December 06, 2017
    • Hello Jaap,
      
      I am trying to schedule this script using batch or schedule task.
      Please assist me on this.
      
      
  • Does this cmdlet work??
    2 Posts | Last post July 28, 2015
    • I am trying to run this on a Windows Server 2008 R2 machine with Excel 2010 installed.
      When I run it from Powershell as follows:
      
      .\Convert-CsvToXlsx.ps1 -Path c:\filename.csv -verbose
      
      Nothing happens. The command prompt returns & when I check the folder, there's no xlsx file.
      
      I also tried running on the folder with multiple csv files as follows:
      Get-ChildItem c:\folderpath\ | .\Convert-CsvToXlsx
      
      Same result: Nothing happens. The command prompt returns & when I check the folder, there's no xlsx file.
      
      I tried updating to Powershell v3.0
      
      Any suggestions?
    • The ps1 file contains a function, so by just executing the script you only load the function to memory for a brief moment. What you could do is dot source to load the function in the script in memory, so it will be available as a function for you to use. Try executing the following code:
      
      # Load function to memory, only needs to be done once per PowerShell session
      . .\Convert-CsvToXlsx.ps1
      # Pipe the output of Get-ChildItem into the Convert-CsvToXlsx function
      Get-ChildItem c:\folderpath\ | Convert-CsvToXlsx