Created
January 3, 2018 22:56
-
-
Save aconz2/37c64738b59d5a00eabb3ff8d2eea3fb to your computer and use it in GitHub Desktop.
convert csv to xlsx with excel
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
param( | |
[parameter(mandatory=$true)] | |
[string]$infile, | |
[parameter(mandatory=$true)] | |
[string]$outfile | |
) | |
# https://msdn.microsoft.com/en-us/vba/excel-vba/articles/workbook-saveas-method-excel | |
$xlOpenXMLWorkbook = 51 | |
$xlLocalSessionChanges = 2 | |
$xl = New-Object -comobject excel.application | |
$wb = $xl.workbooks.open($infile) | |
# SaveAs(FileName , FileFormat , Password , WriteResPassword , ReadOnlyRecommended , CreateBackup , AccessMode , ConflictResolution , AddToMru , TextCodepage , TextVisualLayout , Local) | |
# $wb.saveas($outfile , $xlOpenXMLWorkbook , $Null , $Null , $Null , $Null , $Null , $xlLocalSessionChanges , $Null , $Null , $Null , $Null) | |
# I could never get the xlLocalSessionChanges to work out, so you just have to make sure the outfile doesn't exist yet (or you could add a line to delete it in in this script) | |
$wb.saveas($outfile , $xlOpenXMLWorkbook) | |
$wb.close($False) | |
$xl.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment