CODEKILLER

반응형

DevExpress Gridcontrol에 ExcelDataSource 로드
DevExpress Gridcontrol에 ExcelDataSource 로드

대용량 Excel 파일 DevExpress GridControl에 로드하기

Excel파일의 데이터를 로드하여 GridControl에 컬럼을 파싱 해서 넣어보고, DevExpress SpreadControl을 이용하여 넣어보기도 하였지만, 속도에서 많은 문제가 있었고, 아래의 방법으로는 70만 건 row가 있는 엑셀을 작업했을 때 1.5~2초에 로드가 가능하니 아주 사용할 만합니다. 

 

대신 엑셀파일 내의 동일 컬럼명이 중복으로 들어가 있을 경우에는 자동으로 이름이 바뀌어 버리니, 커스텀컬럼 세팅을 필요할 것 같네요.

openFileDialog1.Filter = "Excel files (*.xls,*xlsx)|*.xls;*xlsx|All files (*.*)|*.*";
openFileDialog1.RestoreDirectory = true;
openFileDialog1.Multiselect = false;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    try
    {
        string filePath = openFileDialog1.FileName;
        var fileName = Path.GetFileName(filePath);

        ExcelDataSource source = new ExcelDataSource();
        source.FileName = filePath;

        ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings();
        worksheetSettings.WorksheetName = "엑셀의 사용하려는 sheet 명";

        ExcelSourceOptions sourceOptions = new ExcelSourceOptions();
        sourceOptions.ImportSettings = worksheetSettings;
        sourceOptions.SkipHiddenRows = false;
        sourceOptions.SkipHiddenColumns = false;
        sourceOptions.UseFirstRowAsHeader = true;
        sourceOptions.SkipEmptyRows = false;

        source.SourceOptions = sourceOptions;
        source.Fill();
        gridControl1.DataSource = source;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band