public void Excel2007(string RaporAdi, DevExpress.XtraGrid.GridControl Liste) { SaveFileDialog Save = new SaveFileDialog(); Save.Filter = "Excel 2007 | *.xlsx"; Save.FileName = RaporAdi; if (Save.ShowDialog() == DialogResult.OK) { Liste.ExportToXlsx(Save.FileName); Process.Start(Save.FileName); } }
public void ExportToGridControl(DevExpress.XtraGrid.GridControl grid) { using (SaveFileDialog saveDialog = new SaveFileDialog()) { saveDialog.Filter = "Excel (*.xlsx)|*.xlsx|Pdf Dosyaları (*.pdf)|*.pdf"; if (saveDialog.ShowDialog() != DialogResult.Cancel) { string exportFilePath = saveDialog.FileName; string fileExtenstion = new FileInfo(exportFilePath).Extension; switch (fileExtenstion) { case ".xlsx": grid.ExportToXlsx(exportFilePath); break; case ".pdf": grid.ExportToPdf(exportFilePath); break; default: break; } if (File.Exists(exportFilePath)) { try { //Try to open the file and let windows decide how to open it. System.Diagnostics.Process.Start(exportFilePath); } catch { String msg = "Dosya Açılamadı." + Environment.NewLine + Environment.NewLine + "Yol: " + exportFilePath; DevExpress.XtraEditors.XtraMessageBox.Show(msg, "Hata!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { String msg = "Dosya Kaydedilemedi." + Environment.NewLine + Environment.NewLine + "Yol: " + exportFilePath; DevExpress.XtraEditors.XtraMessageBox.Show(msg, "Hata!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public bool ExportToExcel(DevExpress.XtraGrid.GridControl gridControl, string userId) { DevExpress.LookAndFeel.UserLookAndFeel lookAndFeel = new DevExpress.LookAndFeel.UserLookAndFeel(gridControl); if (XtraMessageBox.Show(lookAndFeel, "엑셀파일로 저장하시겠습니까?", "파일저장", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Cancel) { return(false); } try { SaveFileDialog oSaveFileDialog = new SaveFileDialog(); oSaveFileDialog.Title = "자신의 엑셀 버전에 맞는 버전을 선택해 주세요."; oSaveFileDialog.Filter = "엑셀 파일(6만건이상) [2007~2013](*.xlsx)|*.xlsx|엑셀 파일(6만건한계) [~2003](*.xls)|*.xls"; oSaveFileDialog.FilterIndex = 1; oSaveFileDialog.RestoreDirectory = true; if (oSaveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (oSaveFileDialog.FileName != null) { bool isCellMerge = false; GridView view = (GridView)gridControl.MainView; isCellMerge = view.OptionsView.AllowCellMerge; view.OptionsView.AllowCellMerge = false; System.IO.FileStream fs = new System.IO.FileStream(oSaveFileDialog.FileName, System.IO.FileMode.Create); if (oSaveFileDialog.FileName.EndsWith(".xls")) { gridControl.ExportToXls(fs); } else { gridControl.ExportToXlsx(fs); } view.OptionsView.AllowCellMerge = isCellMerge; fs.Close(); if (userId == string.Empty) { XtraMessageBox.Show(lookAndFeel, "저장되었습니다.", "저장완료", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } CESFasoo fasoo = new CESFasoo(); CommonFunc.CesnetFasooDrm drm = new CommonFunc.CesnetFasooDrm(); //if (fasoo.FSDEncryption(oSaveFileDialog.FileName, oSaveFileDialog.FileName, "DevExpress 엑셀변환 자료", userId)) //{ if (drm.CESNET2Encryption(oSaveFileDialog.FileName, oSaveFileDialog.FileName, "DevExpress", userId, "0", "", "USP_DRM_CM_FasooDRM_FSN")) { XtraMessageBox.Show(lookAndFeel, "저장되었습니다.", "저장완료", MessageBoxButtons.OK, MessageBoxIcon.Information); Process.Start(oSaveFileDialog.FileName); return(true); } else { throw new CESException("엑셀파일 변환중 암호화에 실패하였습니다."); } } } } catch (Exception ex) { throw new CESException(this, "ConvertExcel", new object[] { }, ex.Message, ex); } return(false); }