DevExpress.XtraExport.ExportXlsProvider實現Excel帶入資料

來源:互聯網
上載者:User
View Code

 1     private void btnImportExcel_Click(object sender, EventArgs e) 2         { 3             if (this.gridView1.RowCount <= 0) 4             { 5                 MessageBox.Show("沒有資料匯入!", "匯入資訊", MessageBoxButtons.OK, MessageBoxIcon.Error); 6             } 7             SaveFileDialog saveExcel = new SaveFileDialog(); 8             saveExcel.Filter = "Excel檔案(.xlsx)|*.xls"; 9             saveExcel.FilterIndex = 1;10             saveExcel.RestoreDirectory = true;11             string newFileName = string.Empty;12             if (saveExcel.ShowDialog() == DialogResult.OK)13             {14                 string localFilePath = saveExcel.FileName.ToString();15                 string localfileNameExt = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));16                 newFileName = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);17                 newFileName = DateTime.Now.ToString("yyyy-MM-dd") + "_" + newFileName;18                 ExportToExcel(localfileNameExt + "\\" + newFileName);19             }20         }

 

View Code

 1   public void ExportToExcel(string fileName) 2         { 3             //this.gridControl1.ExportToXlsx(fileName);    4             try 5             { 6                 if (!string.IsNullOrEmpty(fileName)) 7                 { 8                     ExportTo(gridView1, new DevExpress.XtraExport.ExportXlsProvider(fileName)); 9                 }10             }11             catch (Exception ex)12             {13                 MessageBox.Show(ex.Message.ToString());14             }15         }
View Code

 1   public void ExportTo(DevExpress.XtraGrid.Views.Base.BaseView bv, DevExpress.XtraExport.IExportProvider provider) 2         { 3             Cursor currentCursor = Cursor.Current; 4             Cursor.Current = Cursors.WaitCursor; 5  6             DevExpress.XtraGrid.Export.BaseExportLink link = bv.CreateExportLink(provider); 7             link.ExportTo(true); 8  9             Cursor.Current = currentCursor;10         }
View Code

 1    private void btnSearch_Click(object sender, EventArgs e) 2         { 3             string Where = ""; 4             List<VAV_ACT_SOURCE> SourceList = EntityManager.GetListOfVavActSource(true, false, Where); 5             if (SourceList != null && SourceList.Count > 0) 6             { 7                 gridControl1.DataSource = SourceList; 8             } 9             else10             {11                 VAV_ACT_SOURCE sourcInfo = new VAV_ACT_SOURCE();12                 sourcInfo.CBEHAVIOR = "開機";13                 sourcInfo.CBROADCAST_TIME = DateTime.Now;14                 sourcInfo.CCASN = "20120503";15                 sourcInfo.CCH_ID = 2012050301;16                 sourcInfo.CEND_TIME = DateTime.Now;17                 sourcInfo.CFILENAME = @"c:\Documents and Settings";18                 sourcInfo.CMEMO = "其他說明資訊";19                 sourcInfo.CMSO_ID = 601;20                 sourcInfo.COPERAERT = "收視";21                 sourcInfo.CPRE_CCH_ID = 201;22                 sourcInfo.CSCID = "2012050301";23                 sourcInfo.CSOURCE = "來源資料";24                 sourcInfo.CSTAMP = DateTime.Now;25                 sourcInfo.CSTART_TIME = DateTime.Now;26                 sourcInfo.CTYPE = 0;27                 SourceList.Add(sourcInfo);28 29                 gridControl1.DataSource = SourceList;30             }31         }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.