名前は未だに無し

2019/06/22(土)23:31

【IT】[PowerShell]カリウムの測定値の一覧を作る

IT(3)

先日の「【カリウム】[お茶]その22「ペットボトル」まとめ」のテーブルタグを作るスクリプト。 ※自分用のメモです。 1.読み込みデータ(tsv) 2.スクリプト(ps1) $res  = '<div style="overflow:auto;white-space: nowrap;">'$res += '<table style="width:100%;border: solid 1px #000; border-collapse: collapse;">'$res += '<tr>'$res += '<th rowspan="2" style="text-align:center;border: solid 1px #000;background-color:#ccc;">メーカー</th>'$res += '<th rowspan="2" style="text-align:center;border: solid 1px #000;background-color:#ccc;">品名</th>'$res += '<th rowspan="2" style="text-align:center;border: solid 1px #000;background-color:#ccc;">測定値<br>(ppm)</th>'$res += '<th colspan="4" style="text-align:center;border: solid 1px #000;background-color:#ccc;">メーカー公表値<br>(100mlあたり換算)</th>'$res += '<th rowspan="2" style="text-align:center;border: solid 1px #000;background-color:#ccc;">測定年月</th>'$res += '<th rowspan="2" style="text-align:center;border: solid 1px #000;background-color:#ccc;">備考</th>'$res += '</tr>'$res += '<tr>'$res += '<th style="text-align:center;border: solid 1px #000;background-color:#ccc;">カリウム<br>(mg)</th>'$res += '<th style="text-align:center;border: solid 1px #000;background-color:#ccc;">リン<br>(mg)</th>'$res += '<th style="text-align:center;border: solid 1px #000;background-color:#ccc;">ナトリウム<br>(mg)</th>'$res += '<th style="text-align:center;border: solid 1px #000;background-color:#ccc;">カフェイン<br>(mg)</th>'$res += '</tr>' + "`n"$styles = @('border: solid 1px #000;font-size:0.7rem;','border: solid 1px #000;','text-align:right;background-color:#6fc;border: solid 1px #000;','text-align:right;border: solid 1px #000;','text-align:right;border: solid 1px #000;','text-align:right;border: solid 1px #000;','text-align:right;border: solid 1px #000;','border: solid 1px #000;','border: solid 1px #000;') $rows = (Get-Content .\data.tsv) -as [string[]]for($i = 0; $i -lt $rows.Length; $i++) {  $res += '<tr>'  $cols = $rows[$i] -split "`t"  for($j = 0; $j -lt $cols.Length; $j++) {    if($cols[$j] -ieq 'n/a') {      $res += '<td style="' + $styles[$j] + 'color:#ccc;' + '">' + $cols[$j] + '</td>'    } else {      $res += '<td style="' + $styles[$j] + '">' + $cols[$j] + '</td>'    }  }    $res += '</tr>'  + "`n"}$res += '</table>'$res += '</div>'$res | Out-File -Width 4000 .\res.txt たまにはプログラミングしないと忘れてしまいますね💦

続きを読む

このブログでよく読まれている記事

もっと見る

総合記事ランキング

もっと見る