标签:process idc format roc show write create ted comm
01网络上有很多导出数据到Excel的方法,我在网上找到了一种比较简单实用的方法(参考了网友的方法)
string fileName = ""; Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.DefaultExt = ".xls"; // Default file extension dlg.Filter = "Excel 工作簿|*.xls"; // Filter files by extension // Show save file dialog box Nullable<bool> resultDlg = dlg.ShowDialog(); // Process save file dialog box results if (resultDlg == true) { // Save document fileName = dlg.FileName; } //将DataGrid中的数据导入到excel文件中 Searchresult.SelectAllCells(); Searchresult.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader; ApplicationCommands.Copy.Execute(null, Searchresult); //String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue); String result = (string)Clipboard.GetData(DataFormats.UnicodeText); Searchresult.UnselectAllCells(); //string textToAdd = "Example text in file"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter file1 = new StreamWriter(fs, Encoding.Default); file1.WriteLine(result.Replace(‘,‘, ‘ ‘));
file1.Close();
02 亲测实用
标签:process idc format roc show write create ted comm
原文地址:https://www.cnblogs.com/Record-experience/p/12515216.html