require_once('../../../prod/third/phpexcel/PHPExcel.php');
require_once('../../../prod/third/phpexcel/PHPExcel/IOFactory.php');
//Utilizo un excel plantilla que tengo.
$objTpl = PHPExcel_IOFactory::load("../../../app/MRE/doc/MRE.xls"); $objTpl->setActiveSheetIndex(0);
//set first sheet as active
$query = "SELECT nombre FROM tabla where apellido = 'Escobar'"; $resultado = mysql_query($query);
$total = mysql_num_rows($resultado); while($row = mysql_fetch_array($resultado)) {
// Si dejo este código hasta aqui.. me sale en pantalla el resultado deseado.
//echo $dato ['nombre']; }
//aqui deberia colocarme en la celda E12 los tres nombres del resultado, pero me genera el excel y la casilla está en blanco.
$objTpl->getActiveSheet()->setCellValue('E12' . $row['nombre']);/** Include PHPExcel */
require_once 'PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Thouhedul islam")
->setLastModifiedBy("Thouhedul islam")
->setTitle("PHPExcel Tutorial from tisuchi.com")
->setSubject("PHPExcel Tutorial from tisuchi.com")
->setDescription("This is the tutorial for PHP Excel from tisuchi.com")
->setKeywords("office PHPExcel php")
->setCategory("Tutorial Result");
// Add Data in your file
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Visit ')
->setCellValue('B1', 'tisuchi.com')
->setCellValue('C1', 'for interesting')
->setCellValue('D1', 'tutorail');
$objPHPExcel->getActiveSheet()->setCellValue('A8',"Posted in \n tisuchi.com");
$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1);
$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('tisuchi.com');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, 'http://localhost/php')) , EOL;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
// Echo done
echo " Done writing files" , EOL;
echo $dato ['nombre']; si me muestra el resultado en pantalla como es. Disculpa pero la verdad es que soy muy nuevo.
$cadena = $cadena.$row['nombre'].'-'; echo $row ['nombre'];<?php$cadena = '';$txt1 = 'pablo';$txt2 = 'juan';$cadena = $cadena.$txt1.' - ';$cadena = $cadena.$txt2. ' y fin';echo 'Resultado: '.$cadena;?>
$objTpl->getActiveSheet()->setCellValueExplicit('E12', $row['nombre'], PHPExcel_Cell_DataType::TYPE_STRING);