Imports System.IO Imports System.Text Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim srcFile As String = "C:\temp\1.csv" Dim dstFile As String = "C:\temp\2.csv" Dim sjis As Encoding = Encoding.GetEncoding("Shift_JIS") '評価の一覧として読み込む Dim q = From row In File.ReadLines(srcFile, sjis) Where row <> "" Let cols = row.Split(",") Select row = New With {.姓 = cols(0), .科目 = cols(1), .点数 = CInt(cols(2))} Group By row.姓 Into 国語 = Sum(If(row.科目 = "国語", row.点数, 0)), 数学 = Sum(If(row.科目 = "数学", row.点数, 0)), 英語 = Sum(If(row.科目 = "英語", row.点数, 0)) 'ヘッダ付きcsv形式に変換 Dim csv = {"名前,国語,数学,英語"}.Union(q.Select(Function(row) _ String.Format("{0},{1},{2},{3}", row.姓, row.国語, row.数学, row.英語))) 'ファイルに保存する File.WriteAllLines(dstFile, csv, sjis) End Sub End Class