private void btnExport_Click(object sender, RoutedEventArgs e) { string extension = "xls"; SaveFileDialog dialog = new SaveFileDialog() { DefaultExt = extension, Filter = String.Format("{1} files (.{0})|.{0}|All files (.)|.", extension, "Excel"), FilterIndex = 1 }; if (dialog.ShowDialog() == true) { var col0Visibility = RadGridView1.Columns[0].IsVisible; RadGridView1.Columns[0].IsVisible = false;//ستون هایی که نمی خواهیم در اکسل دیده شوند var opt = new GridViewExportOptions() { Format = ExportFormat.Html, ShowColumnHeaders = true, ShowColumnFooters = true, ShowGroupFooters = false, }; using (Stream stream = dialog.OpenFile()) { RadGridView1.Export(stream, opt); } RadGridView1.Columns[0].IsVisible = col0Visibility;//این ستون در بالا مخفی شده بود، حالا به حالت اول باز گردانده می شود } }
private void Button_Click(object sender, RoutedEventArgs e) { string extension = "xls"; SaveFileDialog dialog = new SaveFileDialog() { DefaultExt = extension, Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"), FilterIndex = 1 }; try { if (dialog.ShowDialog() == true) { radDataPager1.PageSize = 0; using (Stream stream = dialog.OpenFile()) { RadGridView1.Export(stream, new GridViewExportOptions() { Format = ExportFormat.Html, ShowColumnHeaders = true, ShowColumnFooters = true, ShowGroupFooters = false, }); } radDataPager1.PageSize = 18; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }