DevExpress的GridControl中GridView数据导出生成Excel...

发布网友 发布时间:2024-10-24 06:54

我来回答

3个回答

热心网友 时间:2024-11-05 19:00

我就挣点积分来抽奖的

热心网友 时间:2024-11-05 19:02

你是想把combobox里面的下拉值选择都倒出来?

热心网友 时间:2024-11-05 18:59

只保存键值,不用保存显示的值

#region 导出Execl
private void ExportToXls()
{
string fileName = ShowSaveFileDialog("Microsoft Excel Document", "Microsoft Excel|*.xls");
if (fileName != "")
{
ExportTo(new ExportXlsProvider(fileName));
OpenFile(fileName);
}
}
private string ShowSaveFileDialog(string title, string filter)
{
SaveFileDialog dlg = new SaveFileDialog();
string name = " 统计表";
int n = name.LastIndexOf(".") + 1;
if (n > 0) name = name.Substring(n, name.Length - n);
dlg.Title = "Export To " + title;
dlg.FileName = name;
dlg.Filter = filter;
if (dlg.ShowDialog() == DialogResult.OK) return dlg.FileName;
return "";
}
private void ExportTo(IExportProvider provider)
{
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
this.FindForm().Refresh();
BaseExportLink link = gridView1.CreateExportLink(provider);
(link as GridViewExportLink).ExpandAll = false;
//link.Progress += new DevExpress.XtraGrid.Export.ProgressEventHandler(Export_Progress);
link.ExportTo(true);
provider.Dispose();
//link.Progress -= new DevExpress.XtraGrid.Export.ProgressEventHandler(Export_Progress);
Cursor.Current = currentCursor;
}
private void OpenFile(string fileName)
{
if (XtraMessageBox.Show("你想打开这个文件吗??", "文件导出...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = fileName;
process.StartInfo.Verb = "Open";
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.Start();
}
catch
{
DevExpress.XtraEditors.XtraMessageBox.Show(this, "您的系统上无法找到适合打开导出的数据文件的应用程序。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//progressBarControl1.Position = 0;
}
#endregion
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com