C
C#•11mo ago
Core Dream

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
Core DreamOP•11mo 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•11mo ago
$close
MODiX
MODiX•11mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server