文件名称:将DataTable或者数组生成CSV文件C#源码
文件大小:6KB
文件格式:CS
更新时间:2012-05-08 17:13:15
C#,CSV文件,DataTable
SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "*.csv|*.csv"; dialog.DefaultExt = ".csv"; if (dialog.ShowDialog() == DialogResult.OK) { CSVWriter writer = new CSVWriter(); writer.FileName = dialog.FileName; for (int i = 0; i < this.dgvStockList.Rows.Count; i++) { string[] row = new string[this.dgvStockList.Columns.Count]; for (int n = 0; n < this.dgvStockList.Columns.Count; n++) { row[n] = this.dgvStockList.Rows[i].Cells[n].Value.ToString(); } writer.AddData(row); } writer.Save(); }