我導出DataTable行爲CSV文件格式應該是像value,value2,value3等,但我的輸出文件顯示像這樣的值「Value」,「value2」,「value3」 這裏是我的示例代碼Exportingm DataTable csv
Utilities.WriteDataTable(TempTable, writer, true);
public static void WriteDataTable(DataTable sourceTable, TextWriter writer, bool includeHeaders)
{
//Checking if Table has headers :
if (includeHeaders)
{
//Getting Headers:
List<string> headerValues = new List<string>();
foreach (DataColumn column in sourceTable.Columns)
{
headerValues.Add(QuoteValue(column.ColumnName));
}
writer.WriteLine(String.Join(",", headerValues.ToArray()));
}
//fetching rows from DataTable and Putting it in Array
string[] items = null;
foreach (DataRow row in sourceTable.Rows)
{
items = row.ItemArray.Select(o => QuoteValue(o.ToString())).ToArray();
writer.WriteLine(String.Join(",", items));
}
writer.Flush();
}
它看起來您正在調用一個名爲'QuoteValue'的方法來創建您的項目列表。顯然這不是你的代碼。要創建一個適當的CSV,你需要報價。如果數據中有逗號,會怎麼樣? – paqogomez