将wpf datagrid导出到自定义Excel CSV文件
||
我有一个绑定到MVVM集合类的wpf datagrid。而且我具有MVVM类的某些属性,该属性绑定到了datagrid,但不是每个。
我需要从datagrid导出Excel CSV文件中的数据。但是MVVM类的某些属性未绑定到datagrid,但需要在Excel文件中显示。因此,我需要创建自定义列(来自datagrid的列+其他一些列)。
这是我当前用于创建Excel CSV文件的代码:
importedDG.SelectAllCells();
importedDG.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
ApplicationCommands.Copy.Execute(null, importedDG);
importedDG.UnselectAllCells();
string path1 = \"C:\\\\test.csv\";
string result1 = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
Clipboard.Clear();
System.IO.StreamWriter file1 = new System.IO.StreamWriter(path1);
file1.WriteLine(result1);file1.Close();
这将使用DG中的确切列创建文件,但不会包含我想要的其他列。如何添加它们?
没有找到相关结果
已邀请:
1 个回复
犀耽澄协吻