#BASH SCRIPT
<#
SET dir="%~dp0"
Powershell -Command "\FILELOCATION\XLSX-to-CSV.ps1 Convert-CsvInBatch -folderPath \"dir\""
#>
<#main script
HELP
.Dependencies
Requires EXCEL to be installed on the machine
.Parameters
Script will require a path location for the input files
.Expected Outputs
Script will export all .XLSX files in a given directory or given selected files to .CSV files in "X Directory(s)"
#>
#Modify XLSX Document | Open each EXCEL Object | Save as .CSV File
Function Convert-CsvInBatch
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)][String]$Folder
)
#Get all .XLSX files in Directory
$ExcelFiles = Get-ChildItem -Path $Folder -Filter *.xlsx -Recurse
#Creates Excel COMObject
$excelApp = New-Object -ComObject Excel.Application
$excelApp.DisplayAlerts = $false
#For Each File, Delete the Top Row
$ExcelFiles | ForEach-Object {
$workbook = $excelApp.Workbooks.Open($_.FullName)
$csvFilePath= $_.FullName-replace"\.xlsx$",".csv"
#DELETE FIRST 2 ROWS IN EXCEL FILE
$p=1
#Count # of Sheets in Workbook
$i=$workbook.Sheets.Count
while ($p-le$i) {
$sheet=$workbook.Sheets.Item($p)
[void]$sheet.Cells.Item(1,1).EntireRow.Delete()
[void]$sheet.Cells.Item(1,1).EntireRow.Delete()
$p++
}
$workbook.SaveAs($csvFilePath, [Microsoft.Office.Interop.Excel.XlFileFormat]::xlCSV)
$workbook.Close()
}
# Release Excel Com Object resource
$excelApp.Workbooks.Close()
$excelApp.Visible = $true
Start-Sleep 5
$excelApp.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelApp) | Out-Null
}