C
C#•6mo ago
Core Dream Studios

Exporting all model data to a CSV

Hello. I have successfully pulled data out of a custom .sdb (not sqlite), from a old game and was trying to save it to a .CSV so I can import it into a database later (SQLite). I can do the last part just fine but getting a bit lost on the Export side. Thank you in advance.
3 Replies
Core Dream Studios
Core Dream Studios•6mo ago
private void ExportToCSV()
{
var stringBuilder = new StringBuilder();

var headers = StringGridView.Columns.Cast<DataGridViewColumn>();

stringBuilder.AppendLine(string.Join(",", headers.Select(column => "\"" + column.HeaderText + "\"").ToArray()));

foreach (DataGridViewRow row in StringGridView.Rows)
{
var cells = row.Cells.Cast<DataGridViewCell>();
stringBuilder.AppendLine(string.Join(",", cells.Select(cell => "\"" + cell.Value + "\"").ToArray()));
}

File.WriteAllText(Application.StartupPath + @"\outputEnglish.csv", stringBuilder.ToString());
}
private void ExportToCSV()
{
var stringBuilder = new StringBuilder();

var headers = StringGridView.Columns.Cast<DataGridViewColumn>();

stringBuilder.AppendLine(string.Join(",", headers.Select(column => "\"" + column.HeaderText + "\"").ToArray()));

foreach (DataGridViewRow row in StringGridView.Rows)
{
var cells = row.Cells.Cast<DataGridViewCell>();
stringBuilder.AppendLine(string.Join(",", cells.Select(cell => "\"" + cell.Value + "\"").ToArray()));
}

File.WriteAllText(Application.StartupPath + @"\outputEnglish.csv", stringBuilder.ToString());
}
AI helped, it seems to work okay. 🙂
Denis
Denis•6mo ago
$close
MODiX
MODiX•6mo ago
Use the /close command to mark a forum thread as answered