DevExpress&UI

GridControl Data Export to Excel

Code GGOON 2020. 11. 26. 05:23
반응형

Devexpress GrindControl 데이터를 엑셀로 내보내기

/// <summary>
/// 그리드 화면에 있는 데이터를 엑셀로 출력
/// </summary>
/// <param name="grid">그리드 오브젝트</param>
/// <param name="sFileName">파일명</param>
public static void GetGridExportExcel(GridControl grid, string sFileName = "")
{
	SaveFileDialog saveDialog = new SaveFileDialog();
    saveDialog.Filter = "Excel (2010) (.xlsx)|*.xlsx|Excel (2003)(.xls)|*.xls";
    saveDialog.FileName = sFileName + DateTime.Now.ToString("yyyy-MM-dd");
    if (saveDialog.ShowDialog() != DialogResult.Cancel)
    {
    	string exportFilePath = saveDialog.FileName;
        string fileExtenstion = new FileInfo(exportFilePath).Extension;

        switch (fileExtenstion)
        {
        	case ".xls":
            	grid.ExportToXls(exportFilePath);
                break;
            case ".xlsx":
                grid.ExportToXlsx(exportFilePath);
                break;
            default:
                break;
         }
     }
}
반응형