download mysql database to excel in android studio

Solutions on MaxInterview for download mysql database to excel in android studio by the best coders in the world

showing results for - "download mysql database to excel in android studio"
Liah
19 Sep 2017
1<?php
2
3$dbhost= "localhost"; //your MySQL Server 
4$dbuser = "root"; //your MySQL User Name 
5$dbpass = ""; //your MySQL Password 
6$dbname = "smkkimmanuel2"; 
7
8//your MySQL Database Name of which database to use this 
9$tablename = "questions"; //your MySQL Table Name which one you have to create excel file 
10
11// your mysql query here , we can edit this for your requirement 
12$sql = "Select * from pendaftaran "; 
13//create  code for connecting to mysql 
14$Connect = @mysql_connect($dbhost, $dbuser, $dbpass) 
15or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno()); 
16//select database 
17$Db = @mysql_select_db($dbname, $Connect) 
18or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno()); 
19
20error_reporting(E_ALL);
21
22// Create your database query
23$query = "SELECT * FROM pendaftaran";  
24// Execute the database query
25$result = mysql_query($query) or die(mysql_error());
26
27// Instantiate a new PHPExcel object
28 require_once '/PHPExcel_1.8.0_doc/Classes/PHPExcel.php';
29$objPHPExcel = new PHPExcel(); 
30// Set the active Excel worksheet to sheet 0
31$objPHPExcel->setActiveSheetIndex(0); 
32// Set document properties
33$objPHPExcel->getProperties()->setCreator("Wanda")
34			->setLastModifiedBy("Wanda")
35			->setTitle("Office 2007 XLSX Test Document")
36			->setSubject("Office 2007 XLSX Test Document")
37			->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
38			->setKeywords("office 2007 openxml php")
39			->setCategory("Test result file");
40
41
42// Initialise the Excel row number
43$rowCount = 1; 
44// Iterate through each result from the SQL query in turn
45// We fetch each database result row into $row in turn
46while($row = mysql_fetch_array($result)){ 
47    $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['no_pendaftaran']); 
48    $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['jurusan']); 
49    // Increment the Excel row counter
50    $rowCount++; 
51} 
52
53// Redirect output to a client’s web browser (Excel5)
54header('Content-Type: application/vnd.ms-excel');
55header('Content-Disposition: attachment;filename="daftar siswa mendaftar.xls"');
56header('Cache-Control: max-age=0');
57// If you're serving to IE 9, then the following may be needed
58header('Cache-Control: max-age=1');
59
60
61$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
62$objWriter->save('php://output');
63exit;