sysD.rb
===============
# 入力CSVファイル
input_file = 'input.csv'
# 出力HTMLファイル
output_file = 'output.html'
# CSVを読み込む
rows = CSV.read(input_file, headers: true)
# HTML生成
html_content = <<-HTML
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSVデータの表</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
font-family: Arial, sans-serif;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
th {
background-color: #f4f4f4;
}
</style>
</head>
<body>
<h1 style="text-align: center;">CSVデータの表</h1>
<table>
<thead>
<tr>
HTML
# ヘッダー行をHTMLに追加
rows.headers.each do |header|
html_content += " <th>#{header}</th>\n"
end
html_content += " <th>チェック</th>\n" # チェック列のヘッダーを追加
html_content += " </tr>\n </thead>\n <tbody>\n"
# 各行を処理してHTMLに変換
rows.each do |row|
html_content += " <tr>\n"
row.each do |_, value|
html_content += " <td>#{value}</td>\n"
end
# チェックマークを条件に基づいて追加
check_mark = row['Status'] == 'yes' ? '✅' : row['Status'] == 'no'? '❌' : ''
html_content += " <td>#{check_mark}</td>\n"
html_content += " </tr>\n"
end
# HTMLの締め部分
html_content += <<-HTML
</tbody>
</table>
</body>
</html>
HTML
# HTMLファイルを保存
File.write(output_file, html_content)
puts "HTMLファイルが'#{output_file}'に保存されました!"