exceldata.blade.php
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
include_once(app_path().'/lib/phpexcel/PHPExcel.php');
/* $server_ip="10.3.179.121";
$conn = array(
'driver' => 'mysql',
'host' => $server_ip,
'database' => env('DB_DATABASE', 'kstych_flexydial'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'options' => array(
PDO::ATTR_TIMEOUT => 5,
),
);
Config::set("database.connections.conn", $conn);
DB::connection("conn")->getDatabaseName();
*/
$reportarray=DB::select(DB::raw("SELECT * FROM `users` "));
$reporthead=array("id","username","password","fullname","email","status","organization","group","data","presence","timezone","invisible","usertype","diskuse","source","meta","lteam","lteam2","supervisor","created_at","updated_at","remember_token","passwordreset","number1","number2","exten","extencontext","manager");
$inputFileType = "Excel5";
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load("assets/extras/blank.xls");
$baseRow = 3;
$highestColumn = sizeof($reporthead);
for ($head = 0; $head < $highestColumn; $head++){
$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
$objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $reporthead[$head]);
}
foreach($reportarray as $uid=>$uarr)
{
$row = $baseRow++;
$col = 0;
for ($head = 0; $head < $highestColumn; $head++){
$colstr=PHPExcel_Cell::stringFromColumnIndex($head);
$objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $uarr->$reporthead[$head]);
}
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Users_exceldata.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
$objWriter->save('php://output');
return ;
?>