Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ExportAllExcelSheetTo-csv {
- param(
- [System.String]$ExcelFile
- )
- #$Path = 'c:\temp\DSC_ConfigData.xlsx'
- $TempFolder = [System.IO.Path]::GetTempPath()
- $Guid = [System.Guid]::NewGuid()
- $TempDir = Join-Path -Path $TempFolder -ChildPath $Guid.Guid
- New-Item -Path $TempDir -ItemType Directory | Out-Null
- $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite"
- $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
- $workbook = $xl.Workbook
- $targetSheets = $workbook.Worksheets #| Where {$_.Name -like $SheetName}
- #$TempFolder = 'C:\temp'
- foreach ($WorkSheet in $targetSheets) {
- $CSVFileName = $WorkSheet.Name
- $CSVFile = Join-Path -Path $TempDir -ChildPath $CSVFileName
- Import-Excel -Path $File -WorksheetName $WorkSheet.Name | Export-Csv $CSVFile
- }
- dir $TempDir
- }
- ExportAllExcelSheetTo-csv -File 'c:\temp\DSC_ConfigData.xlsx'
Add Comment
Please, Sign In to add comment