Guest User

Untitled

a guest
Mar 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function ExportAllExcelSheetTo-csv {
  2.  
  3. param(
  4. [System.String]$ExcelFile
  5. )
  6. #$Path = 'c:\temp\DSC_ConfigData.xlsx'
  7.  
  8. $TempFolder = [System.IO.Path]::GetTempPath()
  9. $Guid = [System.Guid]::NewGuid()
  10. $TempDir = Join-Path -Path $TempFolder -ChildPath $Guid.Guid
  11. New-Item -Path $TempDir -ItemType Directory | Out-Null
  12.  
  13. $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite"
  14. $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
  15. $workbook = $xl.Workbook
  16.  
  17. $targetSheets = $workbook.Worksheets #| Where {$_.Name -like $SheetName}
  18.  
  19.  
  20. #$TempFolder = 'C:\temp'
  21. foreach ($WorkSheet in $targetSheets) {
  22.  
  23. $CSVFileName = $WorkSheet.Name
  24. $CSVFile = Join-Path -Path $TempDir -ChildPath $CSVFileName
  25. Import-Excel -Path $File -WorksheetName $WorkSheet.Name | Export-Csv $CSVFile
  26.  
  27. }
  28. dir $TempDir
  29. }
  30.  
  31. ExportAllExcelSheetTo-csv -File 'c:\temp\DSC_ConfigData.xlsx'
Add Comment
Please, Sign In to add comment