「レーサー期別成績」をlibreofficeに取り込んだが、うまくいかない箇所があった。
しょうがないので、PowerShellで、固定長のテキストファイルを「,」区切りのCSVファイルに変える
とりあえず、テスト用のコード
# 実行中のパス取得/移動
$path = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $path
$path = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $path
# ファイル読み込み
$fileName = $path + "\fan2010.txt"
$file = New-Object System.IO.StreamReader($fileName, [System.Text.Encoding]::GetEncoding("sjis"))
# 出力ファイル 上書きOK
$textfile = $path +"\test.csv"
$outfile = New-Object System.IO.StreamWriter($textfile, $false, [System.Text.Encoding]::GetEncoding("sjis"))
while (($line = $file.ReadLine()) -ne $null)
{
if( $line.length -le 1){break}
$writeline = $line.Substring( 0, 4);
$writeline = $writeline+","
$writeline = $writeline+$line.Substring( 4, 8);
$writeline = $writeline+","
$writeline = $writeline+$line.Substring( 12, 15);
$writeline = $writeline+","
$writeline = $writeline+$line.Substring( 27, 2);
$writeline = $writeline+","
Write-Host($writeline)
$outfile.WriteLine($writeline)
}
Write-Host("")
$file.Close()
$outfile.Close()
# 終了
Write-Host("終了")
$fileName = $path + "\fan2010.txt"
$file = New-Object System.IO.StreamReader($fileName, [System.Text.Encoding]::GetEncoding("sjis"))
# 出力ファイル 上書きOK
$textfile = $path +"\test.csv"
$outfile = New-Object System.IO.StreamWriter($textfile, $false, [System.Text.Encoding]::GetEncoding("sjis"))
while (($line = $file.ReadLine()) -ne $null)
{
if( $line.length -le 1){break}
$writeline = $line.Substring( 0, 4);
$writeline = $writeline+","
$writeline = $writeline+$line.Substring( 4, 8);
$writeline = $writeline+","
$writeline = $writeline+$line.Substring( 12, 15);
$writeline = $writeline+","
$writeline = $writeline+$line.Substring( 27, 2);
$writeline = $writeline+","
Write-Host($writeline)
$outfile.WriteLine($writeline)
}
Write-Host("")
$file.Close()
$outfile.Close()
# 終了
Write-Host("終了")
上手くいった。
関係ないけど、この間食べたアイス
本日の河上選手:戸田 4日目
1R 6号艇 5コース進入 2着 2万舟