那您帮我看下代码吧
我在下载控件时自带的示例中的DataGrid Samples->ExportFormats中添加了导出Excel的功能。添加的代码如下
xaml代码:
<Button Content="ExportExcel" Grid.Column="1" Click="Button_Click_1"/>
单击事件处理代码:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
var fileDialog = new SaveFileDialog
{
Filter = "Excel(*.xlsx)|*.xlsx",
FilterIndex = 1
};
if (fileDialog.ShowDialog().Value)
{
string filename = fileDialog.FileName;
grid.Save(filename, FileFormat.Xlsx);
}
} |