Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created April 19, 2012 15:05
Show Gist options
  • Save nissuk/2421523 to your computer and use it in GitHub Desktop.
Save nissuk/2421523 to your computer and use it in GitHub Desktop.
C#(.NET 4): DataGridView→CSV(取り急ぎ)
var lines = dataGridView1.Rows.Cast<DataGridViewRow>().Select(row => {
return string.Join(",",
row.Cells.Cast<DataGridViewCell>().Select(cell => {
return string.Format("\"{0}\"", (cell.Value ?? "").ToString().Replace("\"", "\"\""));
})
);
});
File.WriteAllLines("out.csv", lines, Encoding.GetEncoding(932));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment