Guest User

Untitled

a guest
Oct 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <#
  2. The sample scripts are not supported under any Microsoft standard support
  3. program or service. The sample scripts are provided AS IS without warranty
  4. of any kind. Microsoft further disclaims all implied warranties including,
  5. without limitation, any implied warranties of merchantability or of fitness for
  6. a particular purpose. The entire risk arising out of the use or performance of
  7. the sample scripts and documentation remains with you. In no event shall
  8. Microsoft, its authors, or anyone Else involved in the creation, production, or
  9. delivery of the scripts be liable for any damages whatsoever (including,
  10. without limitation, damages for loss of business profits, business interruption,
  11. loss of business information, or other pecuniary loss) arising out of the use
  12. of or inability to use the sample scripts or documentation, even If Microsoft
  13. has been advised of the possibility of such damages
  14. #>
  15.  
  16. $ErrorActionPreference = 'Stop'
  17.  
  18. Function Convert-CsvInBatch
  19. {
  20. [CmdletBinding()]
  21. Param
  22. (
  23. [Parameter(Mandatory=$true)][String]$Folder
  24. )
  25. $ExcelFiles = Get-ChildItem -Path $Folder -Filter *.xlsx -Recurse
  26.  
  27. $excelApp = New-Object -ComObject Excel.Application
  28. $excelApp.DisplayAlerts = $false
  29.  
  30. $ExcelFiles | ForEach-Object {
  31. $workbook = $excelApp.Workbooks.Open($_.FullName)
  32. $csvFilePath = $_.FullName -replace "\.xlsx$", ".csv"
  33. $workbook.SaveAs($csvFilePath, [Microsoft.Office.Interop.Excel.XlFileFormat]::xlCSV)
  34. $workbook.Close()
  35. }
  36.  
  37. # Release Excel Com Object resource
  38. $excelApp.Workbooks.Close()
  39. $excelApp.Visible = $true
  40. Start-Sleep 5
  41. $excelApp.Quit()
  42. [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelApp) | Out-Null
  43. }
  44.  
  45. #
  46. # 0. Prepare the folder path which contains all excel files
  47. # $FolderPath = "D:\var\projects\OCOS\var\excelchange"
  48.  
  49. $FolderPath = "C:\Users\hy092524\Documents\email idd\tatareport"
  50.  
  51. Convert-CsvInBatch -Folder $FolderPath
Add Comment
Please, Sign In to add comment