Created
April 19, 2012 15:05
-
-
Save nissuk/2421523 to your computer and use it in GitHub Desktop.
C#(.NET 4): DataGridView→CSV(取り急ぎ)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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