SparKURS.DAW/Process-ADObjects-Test.ps1
2026-07-06 22:19:54 +02:00

34 lines
1.8 KiB
PowerShell

function TestExcel {
$inputFilePath = "/Users/edmond/Develop/PowerShell/BIT-BV/Data/Z999/In/bitBVTest.xlsx"
$asciiOutputFilePath = "/Users/edmond/Develop/PowerShell/BIT-BV/Data/Z999/In/bitBVTest-ASCII.csv"
$utf8OutputFilePath = "/Users/edmond/Develop/PowerShell/BIT-BV/Data/Z999/In/bitBVTest-UTF8.csv"
$excelInputFile = New-Object -TypeName System.IO.FileStream -ArgumentList @($inputFilePath, [System.IO.FileMode]::Open)
Remove-Item -Path $asciiOutputFilePath -ErrorAction Ignore
Remove-Item -Path $utf8OutputFilePath -ErrorAction Ignore
$excelEngine = New-Object Syncfusion.XlsIO.ExcelEngine
$excelEngine.Excel.DefaultVersion = [Syncfusion.XlsIO.ExcelVersion]::Excel2013
$workBook = $excelEngine.Excel.Workbooks.Open($excelInputFile, [Syncfusion.XlsIO.ExcelOpenType]::Automatic)
$workSheet = $workBook.Worksheets["Tabelle1"]
$rowCount = $workSheet.UsedRange.LastRow
$colCount = $workSheet.UsedRange.LastColumn
for ($i = 2; $i -le $rowCount; $i++) {
outLog ('for ($i = 2; $i -le $rowCount; $i++) iteration: ' + $i)
for ($j = 1; $j -le $colCount; $j++) {
### outLogVerbose 'for ($j = 1; $j -le $colCount; $j++) iteration:' $j
$value = $workSheet.Range[$i, $j].DisplayText
$newValue = $value -replace "`n", " --- " -replace "`r", " --- " -replace ";", "--" -replace "`"", "'"
$workSheet.Range[$i, $j].Text = $newValue
}
}
$utf8Stream = [System.IO.File]::Create($utf8OutputFilePath);
$asciiStream = [System.IO.File]::Create($asciiOutputFilePath);
$workSheet.SaveAs($utf8Stream, ";", [System.Text.Encoding]::UTF8)
$workSheet.SaveAs($asciiStream, ";", [System.Text.Encoding]::ASCII)
$utf8Stream.Close()
$asciiStream.Close()
$workBook.Close($true)
}