Search notes:

PowerShell: Convert CSV files in a directory to Excel Workbooks

This script is iterates over all *.csv files it finds in the specified directory (~\work\2021-03-29) and uses the .NET Microsoft.Office.Interop.Excel namespace to convert the CSV files to workbooks.
set-strictMode -version latest

# add-type -path 'C:\Program Files (x86)\Microsoft Office\Office16\DCF\Microsoft.Office.Interop.Excel.dll'
$assembly = [Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Excel")

$xls = new-object Microsoft.Office.Interop.Excel.ApplicationClass
$xls.Visible = $true

foreach ($csvFile in get-childItem ~\work\2021-03-29\*.csv) {
   write-host "csv file = $csvFile"

   $wb = $xls.Workbooks.Open($csvFile)

   $xlsmFile = $csvFile -replace '\.[^.]+$', '.xlsm'

   if (test-path $xlsmFile) {
      remove-item $xlsmFile
   }
   $wb.SaveAs(
       $xlsmFile,
     #
     #  Following constant specifies format for .xlsm
     # (Compare with https://renenyffenegger.ch/notes/Microsoft/dot-net/namespaces-classes/Microsoft/Office/Interop/_application_/Constants)
      [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbookMacroEnabled
   )
}

$xls.Quit()
$xls = $null
Github repository about-Excel, path: /data-exchange_import-export/CSV/convert-files-in-dir.ps1

See also

The PowerShell example that converts workbooks in a directory to CSV files.
Excel: Importing and displaying CSV data

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1758194330, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Office/Excel/data-exchange_import-export/CSV/ps-convert-files-in-dir(72): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78