-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexportar-excel.php
147 lines (126 loc) · 5.5 KB
/
exportar-excel.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
require 'funciones.php';
require_once 'clases/PHPExcel.php';
require_once 'clases/PHPExcel/Cell/AdvancedValueBinder.php';
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
$query = desencriptar($_GET['query']);
$title = "Listado de miembros chamilo";
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Chamilo")
->setLastModifiedBy("Chamilo")
->setTitle($title);
//$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth('100');
//$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight('100%');
$validLocale = PHPExcel_Settings::setLocale('es');
if (!$validLocale) {
echo "La localización ha fallado\n";
}
$link = conectar();
$result = $link->query($query);
if (!$result) {
die('Invalid query: ' . $link->error);
}
if($result->num_rows > 0){
// Head
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', "Name")
->setCellValue('B1', "Surname")
->setCellValue('C1', 'Country')
->setCellValue('D1', 'E-mail')
->setCellValue('E1', 'Renewal')
->setCellValue('F1', 'Quota')
->setCellValue('G1', 'Type')
->setCellValue('H1', 'Status')
->setCellValue('I1', 'Date Arrival')
->setCellValue('J1', 'Institution')
->setCellValue('K1', 'Address')
->setCellValue('L1', 'Postal Code')
->setCellValue('M1', 'VAT')
->setCellValue('N1', 'Language')
->setCellValue('O1', 'Phone');
$styleArray = array(
'font' => array(
'bold' => true,
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
),
),
);
$styleArray2 = array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => '77BBFF')
)
);
$styleArray3 = array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FAFAFA')
)
);
$objPHPExcel->getActiveSheet()->getStyle('A1:O1')->applyFromArray($styleArray);
$objPHPExcel->getActiveSheet()->getStyle('A1:O1')->applyFromArray($styleArray2);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setAutoSize(true);
$row = 1;
while($aux = $result->fetch_assoc()){
$row ++;
$country = obtener("country","iso",$aux['country'],"printable_name");
$type = obtener("type_member","cod",$aux['type'],"name");
$status = obtener("status","cod",$aux['status'],"status");
$language = obtener("language","cod",$aux['language'],"language");
//Introducimos los datos en la línea del fichero de excel
$objPHPExcel->setActiveSheetIndex(0)
->setCellValueByColumnAndRow(0, $row, $aux['name'])
->setCellValueByColumnAndRow(1, $row, $aux['surname'])
->setCellValueByColumnAndRow(2, $row, $country)
->setCellValueByColumnAndRow(3, $row, $aux['email'])
->setCellValueByColumnAndRow(4, $row, $aux['renewal'])
->setCellValueByColumnAndRow(5, $row, $aux['quota'])
->setCellValueByColumnAndRow(6, $row, $type)
->setCellValueByColumnAndRow(7, $row, $status)
->setCellValueByColumnAndRow(8, $row, $aux['date_arrival'])
->setCellValueByColumnAndRow(9, $row, $aux['institution'])
->setCellValueByColumnAndRow(10, $row, $aux['address'])
->setCellValueByColumnAndRow(11, $row, $aux['postal_code'])
->setCellValueByColumnAndRow(12, $row, $aux['vat'])
->setCellValueByColumnAndRow(13, $row, $language)
->setCellValueByColumnAndRow(14, $row, $aux['phone']);
}
//$objPHPExcel->getActiveSheet()->getStyle('F2:F'.$row)->getNumberFormat()->setFormatCode('#.##');
$objPHPExcel->getActiveSheet()->getStyle('A2:O'.$row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->setCellValue('F'.($row+1), '=SUM(F2:F'.$row.')');
$objPHPExcel->getActiveSheet()->getStyle('F2:F'.($row+1))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
}else{
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'NO ITEM LIST');
}
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="List_Members_Chamilo.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>