-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXLSX2CSV2BDF.ps1
More file actions
executable file
·53 lines (41 loc) · 1.6 KB
/
XLSX2CSV2BDF.ps1
File metadata and controls
executable file
·53 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
cls
Function Convert-Delimiter([regex]$from,[string]$to)
{
begin
{
$z = [char](222)
}
process
{
$_ = $_.Trim()
$_ = $_ -replace "(?:`"((?:(?:[^`"]|`"`"))+)(?:`"$from|`"`$))|(?:$from)|(?:((?:.(?!$from))*.)(?:$from|`$))","$z`$1`$2$z$to"
$_ = $_ -replace "$z(?:$to|$z)?`$","$z"
$_ = $_ -replace "`"`"","`"" -replace "`"","`"`""
$_ = $_ -replace "$z((?:[^$z`"](?!$to))+)$z($to|`$)","`$1`$2"
$_ = $_ -replace "$z","`"" -replace "$z","`""
$_
}
}
#$input = Read-Host "What folder to grab all the xls files"
$files = gci "C:\test\test Bdfs\" -filter "*.xls*"
foreach($file in $files){
write-host $file
$xlCSV = 6
$CSVfilename = [io.path]::ChangeExtension($file.FullName,"csv")
$Excel = New-Object -comobject Excel.Application
$Excel.Visible = $False
$Excel.displayalerts=$False
$Workbook = $Excel.Workbooks.Open($file.FullName)
$Workbook.SaveAs($CSVfilename,$xlCSV)
$Excel.Quit()
Write-Host $CSVfilename
}
$filesCSV = gci "C:\test\test Bdfs\" -filter "*.csv"
foreach($file in $filesCSV){
$bdfFile = [io.path]::ChangeExtension($file.FullName, "bdf")
Get-Content $file.FullName | Convert-Delimiter "," "|" | Set-Content $bdfFile
(Get-Content $bdfFile) | Foreach-Object {$_ -replace "`"`"", "qqqq"} | Set-Content $bdfFile
(Get-Content $bdfFile) | Foreach-Object {$_ -replace "`"", ""} | Set-Content $bdfFile
(Get-Content $bdfFile) | Foreach-Object {$_ -replace "qqqq", "`""} | Set-Content $bdfFile
Write-Host $bdfFile
}