1 回答

TA貢獻1799條經驗 獲得超6個贊
我已經設法找到解決這個問題的方法
首先轉換為 Unicode 文本,然后替換 '\t'與“,” 然后,將其另存為 CSV,代碼如下:
private void ExportToCSV(DataGrid dg)
{
dg.SelectAllCells();
dg.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
ApplicationCommands.Copy.Execute(null, dg);
dg.UnselectAllCells();
String result =(string)Clipboard.GetData(DataFormats.UnicodeText);
string resultCSV = result.Replace('\t',',');
//Save Location for the csv (not the actual Location)
string SaveLocation = @"C:\Users\username\...\values" + ".csv";
//Overwriting previous values after exporting
File.Delete(SaveLocation);
File.AppendAllText(SaveLocation, result,Encoding.UTF8);
}
- 1 回答
- 0 關注
- 227 瀏覽
添加回答
舉報