As the commentators have already noted above, your script incorrectly generates an Excel document.
Excellent article on the topic of working with PHPExcel in Russian is presented here .
Let's try on the basis of the above article to slightly remake your script. Honestly, I did not understand how user names and project names should be related, so do not judge strictly.
<?php require_once ('PHPExcel/Classes/PHPExcel.php'); include('inc/database_connection.php'); $conn = mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME); // ΠΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ Excel2007.php require_once('PHPExcel/Writer/Excel2007.php'); // Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΎΠ±ΡΠ΅ΠΊΡ ΠΊΠ»Π°ΡΡΠ° PHPExcel $xlsx = new PHPExcel(); // Π£ΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ ΠΈΠ½Π΄Π΅ΠΊΡ Π°ΠΊΡΠΈΠ²Π½ΠΎΠ³ΠΎ Π»ΠΈΡΡΠ° $xlsx->setActiveSheetIndex(0); // ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ Π°ΠΊΡΠΈΠ²Π½ΡΠΉ Π»ΠΈΡΡ $sheet = $xlsx->getActiveSheet(); // ΠΠΎΠ΄ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ Π»ΠΈΡΡ $sheet->setTitle('ΠΠΌΡ Π»ΠΈΡΡΠ°'); // Π‘ΡΠΈΠ»Ρ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠ° $HeadStyle = array ( 'fill' => array ( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array ( 'rgb' => 'EAF1DD' ) ), 'font' => array ( 'bold' => true ), 'borders' => array ( 'top' => array ( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array ( 'rgb' => '808080' ) ), 'bottom' => array ( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array ( 'rgb' => '808080' ) ), 'left' => array ( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array ( 'rgb' => '808080' ) ), 'right' => array ( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array ( 'rgb' => '808080' ) ) ), 'alignment' => array ( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, 'wrap' => true ) ); if (isset($_POST['export_excel'])) { $sql="SELECT username FROM user ORDER BY username ASC"; $sql2="SELECT * FROM project"; $result2=mysqli_query($conn, $sql2); if (!$result2) { die('Invalid query: ' . mysqli_error($conn)); } while($row2 = mysqli_fetch_array( $result2)) { $title[] = $row2['title']; } $result=mysqli_query($conn, $sql); if(!$result || mysqli_num_rows($result)>0) { if(isset($title)) { $Column=0; foreach($title as $ttl) { // ΠΠ°ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ Π² ΡΡΠ΅ΠΉΠΊΡ ΠΈΠΌΡ ΠΏΡΠΎΠ΅ΠΊΡΠ° $sheet->setCellValueByColumnAndRow($Column,0,$ttl); // ΠΠ°Π΄Π°ΡΠΌ ΡΡΠ΅ΠΉΠΊΠ΅ ΡΡΠΈΠ»Ρ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠ° - ΡΠ²Π΅Ρ, ΡΡΠΈΡΡ, Π³ΡΠ°Π½ΠΈΡΡ, ΡΠ΅Π½ΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ $sheet->getStyleByColumnAndRow($Column,0)->applyFromArray($HeadStyle); $Column++; } } $Column=0; while($row = mysqli_fetch_array($result)) { // ΠΠ°ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ Π² ΡΡΠ΅ΠΉΠΊΡ ΠΈΠΌΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ $sheet->setCellValueByColumnAndRow($Column,1,$row["username"]); $Column++; } // ΠΡΠ²ΠΎΠ΄ΠΈΠΌ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠΈ header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" ); header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" ); header ( "Cache-Control: no-cache, must-revalidate" ); header ( "Pragma: no-cache" ); header ( "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ); header ( "Content-Disposition: attachment; filename=\"projects.xlsx" ); // ΠΡΠ²ΠΎΠ΄ΠΈΠΌ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ ΡΠ°ΠΉΠ»Π° $objWriter = new PHPExcel_Writer_Excel2007($xlsx); $objWriter->save('php://output'); } } ?>