1
A
回答
1
沒有什麼內置的,但它是相當直接的做你自己。
// Create the CSV file to which grid data will be exported.
StreamWriter sw = new StreamWriter("~/GridData.txt", false);
DataTable dt = GetDataTable(); // Pseudo code
// First we will write the headers.
List<string> columnNames = new List<string>();
foreach (DataColumn column in dt.Columns)
{
columnNames.Add(column.ColumnName);
}
sw.WriteLine(string.Join(",", columnNames.ToArray()));
// Now write all the rows.
int iColCount = dt.Columns.Count;
foreach (DataRow dr in dt.Rows)
{
List<string> columnData = new List<string>();
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
columnData.Add(dr[i].ToString());
}
}
sw.WriteLine(string.Join(",", columnData.ToArray()));
}
sw.Close();
這個代碼肯定會有進一步的優化和改進。我對寫出行的代碼不滿意。
相關問題
- 1. 導出爲CSV(使用內置工具) - 不正確的字符
- 2. 導軌 - CSV(導出爲csv)
- 3. 使用導出Csv
- 4. 使用pymongo將MongoDB導出爲CSV
- 5. 使用OUTFILE將mySQL導出爲CSV
- 6. 使用UNIX將MySQL導出爲CSV
- 7. SQL使用.Net導出爲CSV文件
- 8. 使用Python/Pandas將JSON導出爲CSV
- 9. 使用MVC,C#和jQuery導出爲CSV
- 10. 使用PHP導出爲CSV(在選定的日期範圍內)
- 11. 導出爲CSV表
- 12. 導出爲csv ExtJS
- 13. 導出爲csv wordpress
- 14. Interbase導出爲CSV
- 15. iSeries導出爲CSV
- 16. MongoDB導出爲CSV
- 17. 導出結果上Dbeaver設置爲CSV
- 18. 導軌導出爲CSV
- 19. 使用Powershell將內容輸出爲CSV
- 20. 如何使用導出按鈕導出爲CSV
- 21. Rails導出爲CSV,而不在內存中構建CSV
- 22. 使用R將Redshift中的CSV導出爲CSV PostGreSQL
- 23. 使用PHPExcel CSV導出/導入
- 24. Redis-cli --csv選項(導出爲csv)
- 25. 將查詢導出爲CSV
- 26. 將HIVE導出爲CSV
- 27. Gridview:導出爲csv問題
- 28. MySQLi將表導出爲CSV
- 29. 將Neo4j導出爲.csv
- 30. 將DBgrid導出爲CSV?