Last active
February 24, 2020 01:11
-
-
Save WANGJIEKE/b43a2c301ac3d2477de1dee0a0d6e39b to your computer and use it in GitHub Desktop.
Convert csv to xlsx
This file contains hidden or 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
$excel = New-Object -ComObject Excel.Application | |
$excel.Visible = $false | |
ForEach ($dir in $args) { | |
Write-Output "Converting all csv to xlsx inside $(Resolve-Path $dir)..." | |
Get-ChildItem -Path $(Resolve-Path $dir) | ForEach { | |
if ($_.Extension -ne ".csv") { | |
continue | |
} | |
Write-Output "Converting $_..." | |
$workbook = $excel.Workbooks.Open("$(Resolve-Path $dir)\$_") | |
$workbook.SaveAs("$(Resolve-Path $dir)\$($_.BaseName).xlsx", 51) | |
# 51 here stands for Open XML Workbook format | |
# https://docs.microsoft.com/en-us/office/vba/api/excel.xlfileformat | |
$workbook.Close() | |
} | |
} | |
$excel.Quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment