PHP - Problema al generar un reporte con PHPExcel

 
Vista:
sin imagen de perfil

Problema al generar un reporte con PHPExcel

Publicado por Jeisson (3 intervenciones) el 03/05/2018 23:48:00
Saludos,
Soy nuevo en temas de PHP y estoy tratando de realizar un reporte de Excel a partir de una consulta de mysql usando PHPExcel pero el problema es que a la hora de descargar el archivo el navegador me dice que la pagina no funciona.
Este es mi código.

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
$resultado = $conexion->query($query)
 
	$objPHPExcel = new PHPExcel();
	$objPHPExcel->getProperties()				//se asigna las propiedades del archivo.
				->setCreator("serpajr")
				->setDescription("reporte CDR");
 
	$objPHPExcel->setActiveSheetIndex(0);				//se establece la hoja activa y se le da un titulo.
	$objPHPExcel->getActiveSheet()->setTitle("CDR");
 
	//asignamos los titulos de las columnas.
 
	$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Fecha');
	$objPHPExcel->getActiveSheet()->setCellValue('B5', 'src');
	$objPHPExcel->getActiveSheet()->setCellValue('C5', 'extencion');
	$objPHPExcel->getActiveSheet()->setCellValue('D5', 'dst');
	$objPHPExcel->getActiveSheet()->setCellValue('E5', 'Numero Marcado');
	$objPHPExcel->getActiveSheet()->setCellValue('F5', 'Largo');
	$objPHPExcel->getActiveSheet()->setCellValue('G5', 'dcontext');
	$objPHPExcel->getActiveSheet()->setCellValue('H5', 'lastdata');
	$objPHPExcel->getActiveSheet()->setCellValue('I5', 'Billsec');
	$objPHPExcel->getActiveSheet()->setCellValue('J5', 'Userfield');
	$objPHPExcel->getActiveSheet()->setCellValue('K5', 'Minutos');
	$objPHPExcel->getActiveSheet()->setCellValue('L5', 'Cvecuenta');
	$objPHPExcel->getActiveSheet()->setCellValue('M5', 'NumAsistencia');
	$objPHPExcel->getActiveSheet()->setCellValue('N5', 'Nom Cuenta');
	$objPHPExcel->getActiveSheet()->setCellValue('O5', 'Costo');
	$objPHPExcel->getActiveSheet()->setCellValue('P5', 'Area');
 
	while ($row = $resultado->fetch_assoc())
	{
		$objPHPExcel->getActiveSheet()->setCellValue('A'.$fila, $row['Fecha']);
		$objPHPExcel->getActiveSheet()->setCellValue('B'.$fila, $row['src']);
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$fila, $row['extencion']);
		$objPHPExcel->getActiveSheet()->setCellValue('D'.$fila, $row['dst']);
		$objPHPExcel->getActiveSheet()->setCellValue('E'.$fila, $row['Numero Marcado']);
		$objPHPExcel->getActiveSheet()->setCellValue('F'.$fila, $row['Largo']);
		$objPHPExcel->getActiveSheet()->setCellValue('G'.$fila, $row['dcontext']);
		$objPHPExcel->getActiveSheet()->setCellValue('H'.$fila, $row['lastdata']);
		$objPHPExcel->getActiveSheet()->setCellValue('I'.$fila, $row['Billsec']);
		$objPHPExcel->getActiveSheet()->setCellValue('J'.$fila, $row['Userfield']);
		$objPHPExcel->getActiveSheet()->setCellValue('K'.$fila, $row['Minutos']);
		$objPHPExcel->getActiveSheet()->setCellValue('L'.$fila, $row['Cvecuenta']);
		$objPHPExcel->getActiveSheet()->setCellValue('M'.$fila, $row['NumAsistencia']);
		$objPHPExcel->getActiveSheet()->setCellValue('N'.$fila, $row['Nom Cuenta']);
		$objPHPExcel->getActiveSheet()->setCellValue('O'.$fila, $row['Costo']);
		$objPHPExcel->getActiveSheet()->setCellValue('P'.$fila, $row['Area']);
 
		$fila++;
 
	}
 
 
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="reporte_cdr.xlsx"');
		header('Cache-Control: max-age=0');
		header('Cache-Control: max-age=1');
		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
		header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
		header ('Pragma: public'); // HTTP/1.0
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');
		exit;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 1.071
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema al generar un reporte con PHPExcel

Publicado por Yamil Bracho (888 intervenciones) el 04/05/2018 00:04:05
Que mensaje te muestra el navegador ? Puedes probar quitar la linea donde este el exit;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Problema al generar un reporte con PHPExcel

Publicado por Jeisson (3 intervenciones) el 04/05/2018 00:10:52
hola gracias por tu respuesta el mensaje de los navegadores dice que la pagina no existe.
tambien intente quitando el exit y sale lo mismo.

esta es la consulta mysql.
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
 
	require 'PHPExcel-1.8/Classes/PHPExcel.php';
	require 'conexion.php';
	$fecha_actual = date("Y-m-d")
	$fechai = $_GET['inicio'];
	$fechaf = $_GET['fin'];
	$fila = 6
 
	$query = "select calldate,src,SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) as ext,dst,substring_index(SUBSTRING_INDEX(lastdata,',',1),'/',-1) as Numero_Marcado,length(	substring_index(SUBSTRING_INDEX(lastdata,',',1),'/',-1)) as Largo,dcontext,lastdata,billsec,userfield,ceiling(billsec/60) as MIN_REDONDEO,
		substring_index(userfield,'@',-1) as idcuenta,SUBSTRING_INDEX(SUBSTRING_INDEX(userfield,'@',-3),'@',1) as Asistencia,
		if(substring_index(userfield,'@',-1)='AAF',
		'ASISTENCIA ACE FALABELLA',
			if(substring_index(userfield,'@',-1)='COL',
		'GEA COLOMBIA',
			if(substring_index(userfield,'@',-1)='ASC',
		'ASISTENCIA COLSUBSIDIO',
			if(substring_index(userfield,'@',-1)='LAE',
		'LA ASEGURADORA EMPRESARIAL',
			if(substring_index(userfield,'@',-1)='CMV',
		'COOMEVA MEDICINA PREPAGADA S.A.',
			if(substring_index(userfield,'@',-1)='EDO',
		'SEGUROS DEL ESTADO',
			if(substring_index(userfield,'@',-1)='GCA',
		'GEA COLOMBIA ADMINISTRATIVOS',
			if(substring_index(userfield,'@',-1)='JCO',
		'JURISCOOP',
			if(substring_index(userfield,'@',-1)='VIP',
		'VIP',
			if(substring_index(userfield,'@',-1)='OMN',
		'OMNILIFE',
			if(substring_index(userfield,'@',-1)='PIC',
		'BANCO PICHINCHA S.A.',
			if(substring_index(userfield,'@',-1)='TIG',
		'TIGO',
		  if(substring_index(userfield,'@',-1)='PAN',
		'PAN AMERICAN LIFE',
		    ''))))))))))))
			  ) as cuenta,

		if
		(length(substring_index(replace (lastdata,',300,',''),'/',-1))=16 ,(ceiling(billsec/60)*43),

		            
		(ceiling(billsec/60)*40)
		) as costo,

		if
		(substring_index(replace (lastdata,',300,',''),'/',-1) LIKE '%6767400%', 
			'Redireccionamiento grupo sis',
			if(substring_index(replace (lastdata,',300,',''),'/',-1) like '%3077050%',  
				'Redireccionamiento liberty',
				if(substring_index(replace (lastdata,',300,',''),'/',-1)in(3075459,2119345,5114551),
					'Redireccionamiento seguros del estado',
		        if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '52%',
		            'Cabina',
						if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5301,5304,5312,5311),
		                'Recursos Humanos',
							if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5500,5501,5300),
		                    'Comercial',
								if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5403,5404,5402),
		                        'Proveedores',
									if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1)= 5431,
		                            'Calidad',
										if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5305,5306,5310),
		                                'Finanzas',
											if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5601,5602,5600,5603,5604,5605),
		                                    'TMK administrativo',
												if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '570%',
		                                        'Sistemas',
													if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5900,5901),
		                                            'sala de juntas',
														if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5315,5410,5314),
		                                                'Operaciones',
															if(src = 5565873271,
		                                                    'TMK',
															if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) = 'desdeAgentes',
		                                                    'TMK',
																if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '46%',
																													'Calidad EC',
				'')))))))))))))))

		) as Area

		from asteriskcdrdb.cdr 
		where calldate between '$fechai 00:00:00' and '$fechaf 23:59:59'
		and disposition = 'answered' 
		and lastdata like '%teleone%' 
		and billsec > '0'

		union

		select calldate,src,SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) as ext,dst,substring_index(SUBSTRING_INDEX(lastdata,',',1),'/',-1) as Numero_Marcado,length(substring_index(SUBSTRING_INDEX(lastdata,',',1),'/',-1)) as Largo,dcontext,lastdata,billsec,userfield,ceiling(billsec/60) as MIN_REDONDEO,
		substring_index(userfield,'@',-1) as idcuenta,SUBSTRING_INDEX(SUBSTRING_INDEX(userfield,'@',-3),'@',1) as Asistencia,
		if(substring_index(userfield,'@',-1)='AAF',
		'ASISTENCIA ACE FALABELLA',
			if(substring_index(userfield,'@',-1)='COL',
		'GEA COLOMBIA',
			if(substring_index(userfield,'@',-1)='ASC',
		'ASISTENCIA COLSUBSIDIO',
			if(substring_index(userfield,'@',-1)='LAE',
		'LA ASEGURADORA EMPRESARIAL',
			if(substring_index(userfield,'@',-1)='CMV',
		'COOMEVA MEDICINA PREPAGADA S.A.',
			if(substring_index(userfield,'@',-1)='EDO',
		'SEGUROS DEL ESTADO',
			if(substring_index(userfield,'@',-1)='GCA',
		'GEA COLOMBIA ADMINISTRATIVOS',
			if(substring_index(userfield,'@',-1)='JCO',
		'JURISCOOP',
			if(substring_index(userfield,'@',-1)='VIP',
		'VIP',
			if(substring_index(userfield,'@',-1)='OMN',
		'OMNILIFE',
			if(substring_index(userfield,'@',-1)='PIC',
		'BANCO PICHINCHA S.A.',
			if(substring_index(userfield,'@',-1)='TIG',
		'TIGO',
		  if(substring_index(userfield,'@',-1)='PAN',
		'PAN AMERICAN LIFE',
		    ''))))))))))))
			  ) as cuenta,

		if
		(length(substring_index(replace (lastdata,',300,',''),'/',-1))=12 ,(ceiling(billsec/60)*92), if(length(substring_index(replace (lastdata,',300,',''),'/',-1))like '0456%' ,(ceiling(billsec/91)*662),

		            
		(ceiling(billsec/60)*0)
		)) as costo,

		if
		(substring_index(replace (lastdata,',300,',''),'/',-1) LIKE '%6767400%', 
			'Redireccionamiento grupo sis',
			if(substring_index(replace (lastdata,',300,',''),'/',-1) like '%3077050%',  
				'Redireccionamiento liberty',
				if(substring_index(replace (lastdata,',300,',''),'/',-1)in(3075459,2119345,5114551),
					'Redireccionamiento seguros del estado',
		        if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '52%',
		            'Cabina',
						if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5301,5304,5312,5311),
		                'Recursos Humanos',
							if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5500,5501,5300),
		                    'Comercial',
								if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5403,5404,5402),
		                        'Proveedores',
									if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1)= 5431,
		                            'Calidad',
										if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5305,5306,5310),
		                                'Finanzas',
											if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5601,5602,5600,5603,5604,5605),
		                                    'TMK administrativo',
												if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '570%',
		                                        'Sistemas',
													if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5900,5901),
		                                            'sala de juntas',
														if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5315,5410,5314),
		                                                'Operaciones',
															if(src = 5565873271,
		                                                    'TMK',
															if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) = 'desdeAgentes',
		                                                    'TMK',
																if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '46%',
																													'Calidad EC',
				'')))))))))))))))

		) as Area

		from asteriskcdrdb.cdr 
		where calldate between '$fechai 00:00:00' and '$fechaf 23:59:59'
		and disposition = 'answered' 
		and lastdata like '%claro%' 
		and billsec > '0'

		UNION

		select calldate,src,SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) as ext,dst,substring_index(SUBSTRING_INDEX(lastdata,',',1),'/',-1) as Numero_Marcado,length(substring_index(SUBSTRING_INDEX(lastdata,',',1),'/',-1)) as Largo,dcontext,lastdata,billsec,userfield,ceiling(billsec/60) as MIN_REDONDEO,
		substring_index(userfield,'@',-1) as idcuenta,SUBSTRING_INDEX(SUBSTRING_INDEX(userfield,'@',-3),'@',1) as Asistencia,
		if(substring_index(userfield,'@',-1)='AAF',
		'ASISTENCIA ACE FALABELLA',
			if(substring_index(userfield,'@',-1)='COL',
		'GEA COLOMBIA',
			if(substring_index(userfield,'@',-1)='ASC',
		'ASISTENCIA COLSUBSIDIO',
			if(substring_index(userfield,'@',-1)='LAE',
		'LA ASEGURADORA EMPRESARIAL',
			if(substring_index(userfield,'@',-1)='CMV',
		'COOMEVA MEDICINA PREPAGADA S.A.',
			if(substring_index(userfield,'@',-1)='EDO',
		'SEGUROS DEL ESTADO',
			if(substring_index(userfield,'@',-1)='GCA',
		'GEA COLOMBIA ADMINISTRATIVOS',
			if(substring_index(userfield,'@',-1)='JCO',
		'JURISCOOP',
			if(substring_index(userfield,'@',-1)='VIP',
		'VIP',
			if(substring_index(userfield,'@',-1)='OMN',
		'OMNILIFE',
			if(substring_index(userfield,'@',-1)='PIC',
		'BANCO PICHINCHA S.A.',
			if(substring_index(userfield,'@',-1)='TIG',
		'TIGO',
		  if(substring_index(userfield,'@',-1)='PAN',
		'PAN AMERICAN LIFE',
		    ''))))))))))))
			  ) as cuenta,

		if
		(length(substring_index(replace (lastdata,',300,',''),'/',-1))=16 ,(ceiling(billsec/60)*37),

		            
		(ceiling(billsec/60)*37)
		) as costo,

		if
		(substring_index(replace (lastdata,',300,',''),'/',-1) LIKE '%6767400%',
			'Redireccionamiento grupo sis',
			if(substring_index(replace (lastdata,',300,',''),'/',-1) like '%3077050%',  
				'Redireccionamiento liberty',
				if(substring_index(replace (lastdata,',300,',''),'/',-1)in(3075459,2119345,5114551),
					'Redireccionamiento seguros del estado',
		        if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '52%',
		            'Cabina',
						if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5301,5304,5312,5311),
		                'Recursos Humanos',
							if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5500,5501,5300),
		                    'Comercial',
								if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5403,5404,5402),
		                        'Proveedores',
									if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1)= 5431,
		                            'Calidad',
										if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5305,5306,5310),
		                                'Finanzas',
											if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5601,5602,5600,5603,5604,5605),
		                                    'TMK administrativo',
												if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '570%',
		                                        'Sistemas',
													if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5900,5901),
		                                            'sala de juntas',
														if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) in (5315,5410,5314),
		                                                'Operaciones',
															if(src = 5565873271,
		                                                    'TMK',
															if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) = 'desdeAgentes',
		                                                    'TMK',
																if(SUBSTRING_INDEX(SUBSTRING_INDEX(channel,'-',1),'/',-1) like '46%',
																													'Calidad EC',
				'')))))))))))))))

		) as Area

		from asteriskcdrdb.cdr 
		where calldate between '$fechai 00:00:00' and '$fechaf 23:59:59'
		and disposition = 'answered' 
		and lastdata like '%cellvoz%' 
		and billsec > '0'";
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 1.071
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema al generar un reporte con PHPExcel

Publicado por Yamil Bracho (888 intervenciones) el 04/05/2018 00:25:22
Vamoa ver si tae datos en el while donde recorres las filas, agregale

1
2
3
4
5
while ($row = $resultado->fetch_assoc())
{
    print_r($row);
....
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Problema al generar un reporte con PHPExcel

Publicado por Jeisson (3 intervenciones) el 04/05/2018 15:30:01
Hola ya lo intente pero sigue saliendo lo mismo intente con varios navegadores y en todos me dice que la pagina no existe, la pagina la tengo en un servidor linux debian PHP 5.6 y apache2.

no se que puede estar mal.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar