엑셀 내보내기시 이런 식으로 (모든 컬럼이 최소사이즈로) 출력된다면..

 

 

당황하지 말고

BestFitColumns 메소드를 이용하면 해결됨..

 

단.. BestFitColumns 전에 AutoWith 값을 false로 해줘야함.

 

advBandedGridView.OptionsPrint.AutoWidth = false;
advBandedGridView.OptionsView.ColumnAutoWidth = false;
advBandedGridView.BestFitColumns();

이건 삽질 1시간 짜리임.

 

* 참고 :  https://www.devexpress.com/Support/Center/Question/Details/Q253087

 

 

Tip.하나 더~

 

Band Header width 에 Column Width를 맞추고 싶다면

 

private void BestFitBands(AdvBandedGridView view)
{
            view.BeginUpdate();
            view.OptionsView.ShowColumnHeaders = true;
            foreach (BandedGridColumn col in view.Columns)
                col.Caption = col.OwnerBand.Caption;
            view.BestFitColumns();
            view.OptionsView.ShowColumnHeaders = false;
            view.EndUpdate();
}

 

요기서 발췌함. ( https://www.devexpress.com/Support/Center/Question/Details/Q304079 )

 

 

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

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