엑셀 출력시.. 가장쉬운 방법이

Grid에 Data Binding 한 후 그대로 Export 하는 방법인데..


//

gridControl.ExportToXlsx(path);


했더니 .. 그리드 헤더 부분이 아래처럼 Grouping 되서 출력된다...


문제는 ExportType!


// Export 시, 아래처럼 옵션을 설정할 수 있다

XlsxExportOptionsEx xlsxOptions = new XlsxExportOptionsEx();
xlsxOptions.ShowGridLines = true;   // 라인출력 
xlsxOptions.SheetName = "test";    // sheet 명
xlsxOptions.ExportType = DevExpress.Export.ExportType.WYSIWYG;    // ExportType

gridControl.ExportToXlsx(exportFilePath, xlsxOptions);


WYSIWYG (위지윅)이란? what you see is what you get  (보이는 데로 얻는다. )

보이는 그데로 출력된다는 IT 용어.


 



이제야 내가 의도한데로 나옴.. 삽질 3시간함.


자세한 설명은 아래 링크 참조 ..

https://documentation.devexpress.com/#WindowsForms/CustomDocument17733



하나 더..

그리드에서 Export 할때 유용한 Method ..


http://stackoverflow.com/questions/14583067/devexpress-export-gridview-to-excel


// 위 Link에서 내용 발췌

private void mnuExportTable_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    using (SaveFileDialog saveDialog = new SaveFileDialog())
    {
        saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";
        if (saveDialog.ShowDialog() != DialogResult.Cancel)
        {
            string exportFilePath = saveDialog.FileName;
            string fileExtenstion = new FileInfo(exportFilePath).Extension;

            switch (fileExtenstion)
            {
                case ".xls":
                    gridControl.ExportToXls(exportFilePath);
                    break;
                case ".xlsx":
                    gridControl.ExportToXlsx(exportFilePath);
                    break;
                case ".rtf":
                    gridControl.ExportToRtf(exportFilePath);
                    break;
                case ".pdf":
                    gridControl.ExportToPdf(exportFilePath);
                    break;
                case ".html":
                    gridControl.ExportToHtml(exportFilePath);
                    break;
                case ".mht":
                    gridControl.ExportToMht(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 = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                    MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
             }
             else
             {
                 String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                 MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
        }
    }
}


반응형

+ Recent posts