📜  在android studio中下载mysql数据库到excel - SQL代码示例

📅  最后修改于: 2022-03-11 15:05:29.635000             🧑  作者: Mango

代码示例1
" . mysql_error() . "
" . mysql_errno()); //select database $Db = @mysql_select_db($dbname, $Connect) or die("Couldn't select database:
" . mysql_error(). "
" . mysql_errno()); error_reporting(E_ALL); // Create your database query $query = "SELECT * FROM pendaftaran"; // Execute the database query $result = mysql_query($query) or die(mysql_error()); // Instantiate a new PHPExcel object require_once '/PHPExcel_1.8.0_doc/Classes/PHPExcel.php'; $objPHPExcel = new PHPExcel(); // Set the active Excel worksheet to sheet 0 $objPHPExcel->setActiveSheetIndex(0); // Set document properties $objPHPExcel->getProperties()->setCreator("Wanda") ->setLastModifiedBy("Wanda") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("Test result file"); // Initialise the Excel row number $rowCount = 1; // Iterate through each result from the SQL query in turn // We fetch each database result row into $row in turn while($row = mysql_fetch_array($result)){ $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['no_pendaftaran']); $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['jurusan']); // Increment the Excel row counter $rowCount++; } // Redirect output to a client’s web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="daftar siswa mendaftar.xls"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit;