标签:
#region EXCEL导出 /// <summary> /// EXCEL导出
/// </summary> /// <param name="saveFileName">文件名称</param> /// <param name="gridView">待导出的gridView数据</param> public void ExportToExcel(string saveFileName, DevExpress.XtraGrid.Views.Base.BaseView gridView) { try { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.DefaultExt = "xls"; saveDialog.Filter = "导出Excel(*.xls)|*.xls"; saveDialog.FileName = saveFileName + DateTime.Now.ToString("yyyyMMddHHmmss"); if (saveDialog.ShowDialog() != DialogResult.OK) return; saveFileName = saveDialog.FileName; Cursor.Current = Cursors.WaitCursor; DevExpress.XtraExport.IExportXlsProvider provider = new DevExpress.XtraExport.ExportXlsProvider(saveFileName); this.FindForm().Refresh(); DevExpress.XtraGrid.Export.BaseExportLink link = gridView.CreateExportLink(provider); link.ExportAll = true; 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 = Cursors.Default; MessageUtil.ShowTips("导出成功!"); } catch (Exception ex) {
MessageUtil.ShowError("导出失败!"); } } /// <summary> /// 进度条事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Export_Progress(object sender, DevExpress.XtraGrid.Export.ProgressEventArgs e) { if (e.Phase == DevExpress.XtraGrid.Export.ExportPhase.Link) { // progressBarControl1.Position = e.Position; this.Update(); } } #endregion
标签:
原文地址:http://www.cnblogs.com/xuzai/p/4723340.html