setActiveSheetIndex(0) ->fromArray($export_data, null, 'A1'); // 컬럼 너비 자동 조정 $sheet = $objPHPExcel->getActiveSheet(); foreach (range('A', $sheet->getHighestDataColumn()) as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); } // 💡 기존에 생성된 모든 출력 버퍼를 강제로 비워서, 순수한 파일 데이터만 전송되도록 보장합니다. while (ob_get_level()) { ob_end_clean(); } header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="survey_' . $sv_id . '_' . date('Y-m-d') . '.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; } catch (Exception $e) { // 💡 엑셀 생성 중 오류 발생 시, 깨진 파일을 보내는 대신 명확한 오류 메시지를 출력합니다. die('엑셀 파일 생성 중 오류가 발생했습니다. 오류: ' . htmlspecialchars($e->getMessage())); } } else { // CSV // CSV 다운로드 header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="survey_' . $sv_id . '_' . date('Y-m-d') . '.csv"'); header('Cache-Control: max-age=0'); $output = fopen('php://output', 'w'); // UTF-8 BOM 추가 (엑셀에서 한글 깨짐 방지) fprintf($output, chr(0xEF) . chr(0xBB) . chr(0xBF)); foreach ($export_data as $row) { fputcsv($output, $row); } fclose($output); exit; } } } $g5['title'] = '엑셀 내보내기'; include_once(G5_ADMIN_PATH . '/admin.head.php'); // 설문 목록 가져오기 $survey_list = array(); $survey_sql = "SELECT sv_id, sv_title, sv_created_at, (SELECT COUNT(*) FROM survey_responses WHERE sv_id = sm.sv_id AND sr_status = 'completed') as response_count FROM survey_master sm ORDER BY sv_created_at DESC"; $survey_result = sql_query($survey_sql); while ($survey_row = sql_fetch_array($survey_result)) { $survey_list[] = $survey_row; } ?>
설문 응답 데이터를 엑셀 또는 CSV 형식으로 다운로드할 수 있습니다
Microsoft Excel에서 바로 열 수 있는 형식입니다. 한글 깨짐 없이 데이터를 확인할 수 있으며, 차트나 피벗 테이블 생성에 적합합니다.
범용적인 데이터 형식으로 Google Sheets, R, Python 등 다양한 분석 도구에서 사용할 수 있습니다. 대용량 데이터 처리에 적합합니다.
| ID | 설문 제목 | 응답 수 | 생성일 | 내보내기 |
|---|---|---|---|---|