string extension = "";
ExportFormat format = ExportFormat.Html;
ExportFormat format = ExportFormat.Html;
RadComboBoxItem comboItem = this.rcb_format.SelectedItem as RadComboBoxItem;
string selectedItem = comboItem.Content.ToString();
switch (selectedItem)
{
case "Excel": extension = "xls";
format = ExportFormat.Html;
break;
case "ExcelML": extension = "xml";
format = ExportFormat.ExcelML;
break;
case "Word": extension = "doc";
format = ExportFormat.Html;
break;
case "Csv": extension = "csv";
format = ExportFormat.Csv;
break;
}
SaveFileDialog dialog = new SaveFileDialog();
dialog.DefaultExt = extension;
dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel");
dialog.FilterIndex = 1;
dialog.DefaultFileName = "123.xls";
if (dialog.ShowDialog().Value)
{
using (Stream stream = dialog.OpenFile())
{
GridViewExportOptions exportOptions = new GridViewExportOptions();
exportOptions.Format = format;
exportOptions.ShowColumnFooters = true;
exportOptions.ShowColumnHeaders = true;
exportOptions.ShowGroupFooters = true;
exportOptions.Encoding = UnicodeEncoding.GetEncoding("UTF-8"); //编码格式
this.GridView.Export(stream, exportOptions);
}
}