Skip to content

Instantly share code, notes, and snippets.

@kjeske
Created May 11, 2023 20:37
Show Gist options
  • Select an option

  • Save kjeske/28cf9c3bf1ec6bc2538553a128c59051 to your computer and use it in GitHub Desktop.

Select an option

Save kjeske/28cf9c3bf1ec6bc2538553a128c59051 to your computer and use it in GitHub Desktop.
param ([string]$excelFileName)
Set-ExecutionPolicy Bypass -Scope Process
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "System.Globalization.CultureInfo" "en-US"
Function ExportWSToCSV ($excelPath, $csvFileName)
{
$excelFile = Get-Item $excelPath
$excelLocation = $excelFile.DirectoryName
$E = New-Object -ComObject Excel.Application
$E.Visible = $false
$E.DisplayAlerts = $false
$wb = $E.Workbooks.Open($excelPath)
$ws = $wb.Worksheets[1]
$path = Join-Path -Path $excelLocation -ChildPath ($csvFileName + "_" + $ws.Name + ".csv")
$ws.SaveAs($path, 6)
$E.Quit()
}
ExportWSToCSV -excelPath $excelFileName -csvFileName "out1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment