function generate($generator) { require_once "PHPExcel.php"; $data = $generator->generateExportData(); $this->chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $this->charArray = str_split($this->chars, 1); $objPHPExcel = new PHPExcel(); // set document properties $objPHPExcel->getProperties()->setTitle("Test Data"); // create a first sheet and populate the headings $objPHPExcel->setActiveSheetIndex(0); // hardcoded limitation of 26 x 27 columns (right now) $numCols = count($data["colData"]); for ($i = 0; $i < $numCols; $i++) { $col = $this->getExcelCol($i, 1); $objPHPExcel->getActiveSheet()->setCellValue($col, $data["colData"][$i]); } for ($i = 0; $i < count($data["rowData"]); $i++) { for ($j = 0; $j < $numCols; $j++) { $col = $this->getExcelCol($j, $i + 2); $objPHPExcel->getActiveSheet()->setCellValue($col, $data["rowData"][$i][$j]); } } // redirect output to a client’s web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="01simple.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; }
function create() { //load our new PHPExcel library $this->load->library('excel'); //activate worksheet number 1 $this->excel->setActiveSheetIndex(0); //name the worksheet $this->excel->getActiveSheet()->setTitle('test worksheet'); //set cell A1 content with some text $this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value'); //change the font size $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20); //make the font become bold $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); //merge cell A1 until D1 $this->excel->getActiveSheet()->mergeCells('A1:D1'); //set aligment to center for that merged cell (A1 to D1) $this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $filename = 'just_some_random_name.xls'; //save our workbook as this file name header('Content-Type: application/vnd.ms-excel'); //mime type header('Content-Disposition: attachment;filename="' . $filename . '"'); //tell browser what's the file name header('Cache-Control: max-age=0'); //no cache //save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type) //if you want to save it as .XLSX Excel 2007 format $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); //force user to download the Excel file without writing it to server's HD $objWriter->save('php://output'); }
function createExcel($no_telp, $npwd) { ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); date_default_timezone_set('Europe/London'); define('EOL', PHP_SAPI == 'cli' ? PHP_EOL : '<br />'); /** Include PHPExcel */ require_once dirname(__FILE__) . '/Classes/PHPExcel.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set document properties $objPHPExcel->getProperties()->setCreator("Disyanjak Bandung")->setLastModifiedBy("Disyanjak Bandung")->setTitle("Daftar SMS")->setSubject("Daftar SMS")->setDescription("Daftar SMS untuk ke WP")->setKeywords("office PHPExcel php")->setCategory("Test result file"); $objPHPExcel->getActiveSheet()->getStyle('A2')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER); // Add some data $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Phone No.')->setCellValue('A2', $no_telp); //$objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1); //$objPHPExcel->getActiveSheet()->setCellValue('A8',"Hello\nWorld"); //$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1); //$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true); // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('Daftar SMS'); // 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'); $fileName = 'send_sms_' . $npwd; $objWriter->save($fileName . '.xlsx'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save($fileName . '.xls'); return $fileName; }
public function actionExportExcel() { $model = new Reporte(); $evento_id = $_POST['Report']['evento_id']; $sector_id = $_POST['Report']['sector_id']; $subsector_id = $_POST['Report']['subsector_id']; $rama_actividad_id = $_POST['Report']['rama_actividad_id']; $actividad_id = $_POST['Report']['actividad_id']; $dataReporte = $model->search($evento_id, $sector_id, $subsector_id, $rama_actividad_id, $actividad_id); $objExcel = new PHPExcel(); $objExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Nombre')->setCellValue('B1', 'Cédula')->setCellValue('C1', 'Celular')->setCellValue('D1', 'Teléfono')->setCellValue('E1', 'E-mail')->setCellValue('F1', 'Dirección')->setCellValue('G1', 'Sector')->setCellValue('H1', 'Subsector')->setCellValue('I1', 'Rama de Actividad')->setCellValue('J1', 'Actividad'); $id = 2; foreach ($dataReporte as $Reporte) { $objExcel->setActiveSheetIndex(0)->setCellValue('A' . $id, $Reporte['nombre_completo'])->setCellValue('B' . $id, $Reporte['cedula'])->setCellValue('C' . $id, $Reporte['celular'])->setCellValue('D' . $id, $Reporte['telefono'])->setCellValue('E' . $id, $Reporte['email'])->setCellValue('F' . $id, $Reporte['direccion'])->setCellValue('G' . $id, $Reporte['sector'])->setCellValue('H' . $id, $Reporte['subsector'])->setCellValue('I' . $id, $Reporte['rama_actividad'])->setCellValue('J' . $id, $Reporte['actividad']); $id++; } for ($i = 'A'; $i <= 'O'; $i++) { $objExcel->setActiveSheetIndex(0)->getColumnDimension($i)->setAutoSize(TRUE); } $objExcel->getActiveSheet()->setTitle('ReporteParticipantes'); //// Se activa la hoja para que sea la que se muestre cuando el archivo se abre $objExcel->setActiveSheetIndex(0); // //// Inmovilizar paneles $objExcel->getActiveSheet(0)->freezePane('A4'); $objExcel->getActiveSheet(0)->freezePaneByColumnAndRow(1, 2); // Se manda el archivo al navegador web, con el nombre que se indica, en formato 2007 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="ReporteParticipantes.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007'); $objWriter->save('php://output'); exit; }
function get_comments_xls($filename, $cons) { require_once TEMPLATEPATH . '/app/PHPExcel.php'; global $wpdb; $sql = "SELECT post_title,comment_ID,comment_author, comment_date_gmt, comment_content\n\t\t\tFROM {$wpdb->comments}\n\t\t\t\tLEFT OUTER JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID)\n\t\t\t\tINNER JOIN {$wpdb->term_relationships} as r1 ON ({$wpdb->posts}.ID = r1.object_id)\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} as t1 ON (r1.term_taxonomy_id = t1.term_taxonomy_id)\n\t\t\tWHERE comment_approved = '1'\n\t\t\t\tAND comment_type = ''\n\t\t\t\tAND post_password = ''\n\t\t\t\tAND t1.taxonomy = 'category'\n\t\t\t\tAND t1.term_id = " . $cons . "\n\t\t\torder by comment_date_gmt"; $qr = $wpdb->get_results($sql, ARRAY_N); // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("Consultator")->setLastModifiedBy("Consultator")->setTitle("Consultator")->setSubject("Consultator")->setDescription("Αρχείο Εξαγωγής Σχολίων")->setKeywords("Σχόλια")->setCategory("Αρχείο Σχολίων"); // Add some data // Headers $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Άρθρο')->setCellValue('B1', 'Κωδικός Σχολίου')->setCellValue('C1', 'Σχολιαστής')->setCellValue('D1', 'Ημερομηνία Υποβολής')->setCellValue('E1', 'Σχόλιο'); $objPHPExcel->getActiveSheet()->fromArray($qr, NULL, 'A2'); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Σχόλια Διαβούλευσης'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $filename . '.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); $objPHPExcel->disconnectWorksheets(); unset($objPHPExcel); exit; }
public function test_read_write_excel() { $inputFileName = 'print_docs/excel/excel_template/KEMSA Customer Order Form.xlsx'; $inputFileType = PHPExcel_IOFactory::identify($inputFileName); // echo "$inputFileType";die; $file_name = time() . '.xlsx'; $excel2 = PHPExcel_IOFactory::createReader($inputFileType); $excel2 = $objPHPExcel = $excel2->load($inputFileName); // Empty Sheet $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); $excel2->setActiveSheetIndex(0); $excel2->getActiveSheet()->setCellValue('H4', '4')->setCellValue('H5', '5')->setCellValue('H6', '6')->setCellValue('H7', '7')->setCellValue('H8', '7'); // Loop through each row of the worksheet in turn for ($row = 1; $row <= $highestRow; $row++) { // Read a row of data into an array $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE); if (isset($rowData[0][2]) && $rowData[0][2] != 'Product Code') { $excel2->getActiveSheet()->setCellValue("H{$row}", '7'); } } $objWriter = PHPExcel_IOFactory::createWriter($excel2, $inputFileType); $objWriter->save("print_docs/excel/excel_files/" . $file_name); }
public function run($args) { Yii::import('application.components.PHPExcel.PHPExcel.PHPExcel_IOFactory'); Yii::import('application.modules.store.models'); $inputFileName = Yii::getPathOfAlias('application.components.spreadsheetReader.translates') . '/' . 'cargotogo_products.xlsx'; $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load($inputFileName); $db = \Yii::app()->db; $max_id = $db->createCommand()->select('MAX(id)')->from('site_store_product')->queryScalar(); $row = 1; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Наименование')->setCellValue('B1', 'Ссылка')->setCellValue('C1', 'Регион')->setCellValue('D1', 'Название подраздела')->setCellValue('E1', 'Ссылка на подраздел ')->setCellValue('F1', 'Название раздела (верхний уровень)')->setCellValue('G1', 'Название раздела (второй уровень)')->setCellValue('H1', 'Ссылка на раздел (второй уровень)'); $row++; $data = []; for ($i = 1; $i <= $max_id; $i++) { $db->setActive(true); $product = $db->createCommand()->select('id, name, slug, category_id')->from('site_store_product')->where('id=' . $i)->queryRow(); if (!empty($product)) { echo $product['id'] . "\n"; $region = $db->createCommand()->select('value')->from('site_store_product_attribute_eav')->where('product_id=' . $product['id'] . ' AND attribute="adres_name"')->queryRow(); if (!empty($product['category_id'])) { $category = $db->createCommand()->select('id, slug, parent_id, name_ru')->from('site_store_category')->where('id=' . $product['category_id'])->queryRow(); } $data = ['name' => $product['name'], 'link' => 'http://cargotogo.com/store/show/' . $product['slug'], 'region' => isset($region) ? $region['value'] : '', 'sub_category_name' => isset($category) ? $category['name_ru'] : '', 'sub_category_link' => isset($category) ? 'http://cargotogo.com/store/' . $this->getParentStoreCategoriesLink($category, $db) : '', 'main_category_name' => isset($category) ? $this->getMainStoreCategoryName($category, $db) : '', 'second_category_name' => isset($category) ? $this->getSecondStoreCategoryName($category, $db) : '', 'second_category_link' => isset($category) ? 'http://cargotogo.com/store/' . $this->getSecondStoreCategoryLink($category, $db) : '']; $objPHPExcel->getActiveSheet()->setCellValue('A' . $row, $data['name'])->setCellValue('B' . $row, $data['link'])->setCellValue('C' . $row, $data['region'])->setCellValue('D' . $row, $data['sub_category_name'])->setCellValue('E' . $row, $data['sub_category_link'])->setCellValue('F' . $row, $data['main_category_name'])->setCellValue('G' . $row, $data['second_category_name'])->setCellValue('H' . $row, $data['second_category_link']); $row++; } } $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save($inputFileName); }
public static function downloadExcelFileByArray($data, $fileName = '') { self::prepare(); if (!$fileName) { $fileName = 'xls-download-' . date('Y-m-d-H-i-s') . '.xls'; } $objPHPExcel = new \PHPExcel(); $objPHPExcel->getActiveSheet()->fromArray($data); $objPHPExcel->getActiveSheet()->freezePane('A2'); // Redirect output to a client’s web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $fileName . '"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; }
/** * This function will handle the download Action * This takes three parameters and generated the excel file * @coupontype : This parameter will hold the value of coupon type [deal=>1 | coupon=>0] * @store : This parameter will hold the value of website ID * @category : This parameter will hold the value of category ID * @return filtered coupons to search view */ public function actionDownload($couponType, $Stores, $Category) { $coupontype = $_GET['couponType']; $store = isset($_GET['Stores']) ? $_GET['Stores'] : "all"; $category = isset($_GET['Category']) ? $_GET['Category'] : "all"; $coupons = $this->extractData(Coupon::find(), $category, $store, $category); $excel = new PHPExcel(); $excel->getActiveSheet()->setCellValue('B1', "Title")->setCellValue('C1', "Website Name")->setCellValue('D1', "Coupon Code")->setCellValue('E1', "Description"); $i = 2; foreach ($coupons as $coupon) { $excel->getActiveSheet()->setCellValue('B' . $i, $coupon->Title)->setCellValue('C' . $i, $coupon->website->WebsiteName)->setCellValue('D' . $i, $coupon->CouponCode)->setCellValue('E' . $i, $coupon->Description); $i++; } // Naming the active spread sheet $excel->getActiveSheet()->setTitle('List Of Coupons'); $excel->setActiveSheetIndex(0); // Redirect output to a clients web browser (Excel5) header('Cache-Control: max-age=0'); $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5'); // We'll be outputting an excel file header('Content-type: application/vnd.ms-excel'); // It will be called file.xls header('Content-Disposition: attachment; filename="result.xls"'); // Write file to the browser $objWriter->save('php://output'); }
public function exportExcel($objPHPExcel, $versionExcel = '', $fileName = '') { //2003 use 'Excel5' $extFile = $versionExcel == 'Excel2007' ? ".xlsx" : ".xls"; if ($fileName == "") { $fileName = date("yMdhis") . $extFile; } // Redirect output to a client’s web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $fileName . '"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $versionExcel); $objWriter->save('php://output'); exit; }
public function enviar_mail($ext, $informacion, $empresa, $nom_archivo) { $fecha_actual = date("Y-m-d H:i:s"); $nombreFullArchivo = $empresa->nombre . "-" . $nom_archivo . "-" . $fecha_actual; $doc_root = $_SERVER["DOCUMENT_ROOT"]; $enlace = "reportes/" . $nombreFullArchivo . $ext; $url_full = $doc_root . "/cambari/" . $enlace; if (strcasecmp($ext, ".txt") == 0) { $fp = fopen($url_full, "x"); fwrite($fp, $informacion); fclose($fp); $rta = $this->sendMail($empresa->persona_contacto, $url_full); $datos = array("fecha" => $fecha_actual, "url_archivo" => $enlace, "mensaje_mail" => $rta); return $datos; } else { if (strcasecmp($ext, ".xls") == 0) { $informacion->getProperties()->setCreator("kubesoft Generator")->setTitle($nombreFullArchivo)->setSubject("Reporte Recaudos " . $empresa->nombre)->setDescription("Reporte de Recaudos " . $empresa->nombre)->setCategory("Reporte excel"); //Categorias // Se activa la hoja para que sea la que se muestre cuando el archivo se abre $informacion->setActiveSheetIndex(0); $objWriter = PHPExcel_IOFactory::createWriter($informacion, 'Excel5'); $objWriter->save($doc_root . "/multipagos/" . $enlace); $rta = $this->sendMail($empresa->persona_contacto, $url_full); $datos = array("fecha" => $fecha_actual, "url_archivo" => $enlace, "mensaje_mail" => $rta); return $datos; } } }
/** * Genera excel con los datos de la tabla */ public function excel() { $this->_setDataTable(); $this->_addPlugin(); $letras = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); $this->load->lib("Vendor/PHPExcel", false); $this->_objPHPExcel = new PHPExcel(); $this->_objPHPExcel->getProperties()->setCreator("Sumanet 3.0")->setLastModifiedBy("Sumanet 3.0")->setTitle("Exportación de expedientes")->setSubject("Sumanet")->setDescription($this->_title)->setKeywords("office 2007 openxml php sumanet")->setCategory("Sumanet"); $i = 0; foreach ($this->_data["columns"] as $columna) { if (count($columna) > 0) { $this->_objPHPExcel->setActiveSheetIndex(0)->setCellValue($letras[$i] . '1', strip_tags($columna["column_name"])); $i++; } } $this->_filasExcel($letras); $this->_objPHPExcel->getActiveSheet()->setTitle($this->_title); $this->_objPHPExcel->setActiveSheetIndex(0); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $this->_title . '.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($this->_objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; }
public function export($content, $title = '报表', $SavePath = null) { $objPHPExcel = $this->objPHPExcel; // Set properties $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2003 XLSX Test Document")->setSubject("Office 2003 XLSX Test Document")->setDescription("Test document for Office 2003 XLSX, generated using PHP classes.")->setKeywords("office 2003 openxml php")->setCategory("Test result file"); // Set default font $objPHPExcel->getDefaultStyle()->getFont()->setName('宋体'); $objPHPExcel->getDefaultStyle()->getFont()->setSize(12); // Add some data, resembling some different data types $trid = 1; foreach ($content as $tr) { $tdtotal = 0; foreach ($tr as $td) { $tdid = intval($tdtotal / 26) >= 1 ? chr(ord('A') + intval($tdtotal / 26) - 1) . chr(ord('A') + $tdtotal % 26) : chr(ord('A') + $tdtotal % 26); $objPHPExcel->getActiveSheet()->setCellValue($tdid . $trid, $td); $tdtotal++; } $trid++; } //Set Width for ($i = 0; $i < $tdtotal; $i++) { $tdid = intval($i / 26) >= 1 ? chr(ord('A') + intval($i / 26) - 1) . chr(ord('A') + $i % 26) : chr(ord('A') + $i % 26); $objPHPExcel->getActiveSheet()->getColumnDimension($tdid)->setWidth(12); } // Rename sheet $objPHPExcel->getActiveSheet()->setTitle($title); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Save Excel 2003 file $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $SavePath = $SavePath ? $SavePath : ROOT_PATH . '/sites/3i/data/' . date('YmdHis') . '.xls'; $objWriter->save($SavePath); return $SavePath; }
/** * @brief 将数组导出成为excel文件记录 * * @param array $data 数组,数组的第一个元素是数组的相关模板信息 * @param string $type 导出的excel文件类型 * @return public function * @retval * @see * @note * @author 吕宝贵 * @date 2016/01/02 23:46:49 **/ public function exportToExcel(array $data, array $meta, $type = 1) { //字符集转换,excel使用gbk字符集 array_walk($meta, [$this, 'convertToGBK']); $this->objPHPExcel->getProperties()->setCreator($meta['author'])->setLastModifiedBy($meta['modify_user'])->setTitle($meta['title'])->setSubject($meta['subject'])->setDescription($meta['description'])->setKeywords($meta['keywords'])->setCategory($meta['category']); $this->objPHPExcel->setActiveSheetIndex(0); $objActiveSheet = $this->objPHPExcel->getActiveSheet(); $objActiveSheet->setTitle($meta['title']); $columnCount = count($data[0]); $rowIndex = 1; foreach ($data as $payable) { //Excel的第A列,uid是你查出数组的键值,下面以此类推 $currentCharAscii = 64; for ($columnIndex = 0; $columnIndex < $columnCount; $columnIndex++) { $currentCharAscii += 1; $objActiveSheet->setCellValueExplicit(chr($currentCharAscii) . $rowIndex, $payable[$columnIndex], \PHPExcel_Cell_DataType::TYPE_STRING); } $rowIndex += 1; } $filename = $meta['filename']; $this->objPHPExcel->getActiveSheet()->setTitle('明细记录'); $this->objPHPExcel->setActiveSheetIndex(0); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $filename . '.xls"'); header('Cache-Control: max-age=0'); $objWriter = \PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'Excel5'); $objWriter->save('php://output'); return true; }
public static function run($debug = false, $mailOut = true) { try { self::$_debug = $debug; if ($debug) { echo '<pre>'; } $objPHPExcel = self::_getOutput(); if (!$objPHPExcel instanceof PHPExcel) { throw new Exception('System Error: can NOT generate CSV without PHPExcel object!'); } // Set document properties $filePath = self::$_rootDir . '/' . md5(new UDate()) . '.csv'; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')->setDelimiter(',')->setEnclosure('"')->setLineEnding("\r\n")->setSheetIndex(0); ob_start(); $objWriter->save('php://output'); $excelOutput = ob_get_clean(); $class = get_called_class(); $asset = Asset::registerAsset($class::_getAttachedFileName(), $excelOutput, Asset::TYPE_TMP); if ($mailOut === true) { self::_mailOut($asset); } return $asset; } catch (Exception $ex) { echo $ex->getMessage(); die('ERROR!'); } }
protected function footer($objPHPExcel, $start, $file_name, $format, $html_title) { $start++; $jemaat = get_jemaat_from_user_id(Yii::app()->user->getId()); $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Dicetak oleh: " . $jemaat->real_name); $start++; $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Pada tanggal " . get_date_today('dd/MM/yyyy') . " jam " . get_time_now()); ob_end_clean(); ob_start(); if ($format == 'excel') { header('Content-Type: application/vnd.ms-excel'); header("Content-Disposition: attachment;filename={$file_name}.xls"); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); } else { $objPHPExcel->getActiveSheet()->setShowGridlines(false); $mPDF1 = Yii::app()->ePdf->mpdf(); $mPDF1 = Yii::app()->ePdf->mpdf('', 'A4'); $objWriter = new PHPExcel_Writer_HTML($objPHPExcel); $header = $objWriter->generateHTMLHeader(true); $header = str_replace("<body>", "<body onload='window.print();'>", $header); $header = str_replace("Untitled Spreadsheet", $html_title, $header); $html = $header . $objWriter->generateStyles(true) . $objWriter->generateSheetData() . $objWriter->generateHTMLFooter(); if ($format == 'pdf') { $mPDF1->WriteHTML($html); $mPDF1->Output('MutasiKasDitangan.pdf', 'D'); } else { echo $html; } } }
function save_sheet($xls_obj, $dirTemp, $titre) { // Nom de l'onglet courant $xls_obj->getActiveSheet()->setTitle("{$titre}"); // if(isset($_POST['date1']) && $_POST['date1'] && isset($_POST['date2']) && $_POST['date2']){ // $d1 = $_POST['date1']; // $d2 = $_POST['date2']; // $d1f = preg_replace("/(\d{2})\/(\d{2})\/(\d{4})/","$3$2$1",$d1); // $d2f = preg_replace("/(\d{2})\/(\d{2})\/(\d{4})/","$3$2$1",$d2); // $filename= "$dirTemp" . "$titre$d1f".'_'. "$d2f.xlsx"; // }else{ // $filename= "$dirTemp" . mt_rand(1,100000).'.xlsx'; // } $filename = "{$dirTemp}" . mt_rand(1, 100000) . '.xlsx'; $objWriter = PHPExcel_IOFactory::createWriter($xls_obj, 'Excel2007'); $objWriter->save($filename); header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/download'); header("Content-Disposition: attachment;filename={$filename}"); header('Content-Transfer-Encoding: binary'); $objWriter->save('php://output'); unlink($filename); }
function export() { $model = M("Contact"); $where['user_id'] = array('eq', get_user_id()); $list = $model->where($where)->select(); //导入thinkphp第三方类库 Vendor('Excel.PHPExcel'); $inputFileName = C("SAVE_PATH") . "templete/contact.xlsx"; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $objPHPExcel->getProperties()->setCreator("小薇")->setLastModifiedBy("小薇")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file"); // Add some data $i = 1; //dump($list); foreach ($list as $val) { $i++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$i}", $val["name"])->setCellValue("B{$i}", $val["company"])->setCellValue("C{$i}", $val["dept"])->setCellValue("D{$i}", $val["position"])->setCellValue("E{$i}", $val["office_tel"])->setCellValue("F{$i}", $val["mobile_tel"])->setCellValue("G{$i}", $val["email"])->setCellValue("H{$i}", $val["im"])->setCellValue("I{$i}", $val["website"])->setCellValue("J{$i}", $val["address"])->setCellValue("J{$i}", $val["remark"]); } // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('Contact'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $file_name . '"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; }
private function genSheet() { $this->xlsobj = PHPExcel_IOFactory::createWriter($this->xlsobj, 'Excel2007'); $filename = $this->xlsName ? $this->xlsName . 'xlsx' : str_replace('.php', '', strtotime('now')) . '.xlsx'; $this->xlsobj->save($filename); return $filename; }
function export() { $model = M("Customer"); $where['is_del'] = 0; $list = $model->where($where)->select(); Vendor('Excel.PHPExcel'); //导入thinkphp第三方类库 $inputFileName = "Public/templete/customer.xlsx"; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $objPHPExcel->getProperties()->setCreator("smeoa")->setLastModifiedBy("smeoa")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file"); // Add some data $i = 1; //dump($list); foreach ($list as $val) { $i++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$i}", $val["name"])->setCellValue("B{$i}", $val["short"])->setCellValue("C{$i}", $val["biz_license"])->setCellValue("D{$i}", $val["payment"])->setCellValue("E{$i}", $val["address"])->setCellValue("F{$i}", $val["salesman"])->setCellValue("G{$i}", $val["contact"])->setCellValue("H{$i}", $val["email"])->setCellValue("I{$i}", $val["office_tel"])->setCellValue("J{$i}", $val["mobile_tel"])->setCellValue("J{$i}", $val["fax"])->setCellValue("L{$i}", $val["im"])->setCellValue("M{$i}", $val["remark"]); } // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('Customer'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); $file_name = "customer.xlsx"; // Redirect output to a client’s web browser (Excel2007) header("Content-Type: application/force-download"); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header("Content-Disposition:attachment;filename =" . str_ireplace('+', '%20', URLEncode($file_name))); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; }
public function stream($filename, $data = null) { if ($data != null) { $col = 'A'; foreach ($data[0] as $key => $val) { $objRichText = new PHPExcel_RichText(); $objPayable = $objRichText->createTextRun(str_replace("_", " ", $key)); $this->excel->getActiveSheet()->getCell($col . '1')->setValue($objRichText); $col++; } $rowNumber = 2; foreach ($data as $row) { $col = 'A'; foreach ($row as $cell) { $this->excel->getActiveSheet()->setCellValue($col . $rowNumber, $cell); $col++; } $rowNumber++; } } header('Content-type: application/ms-excel'); header("Content-Disposition: attachment; filename=\"" . $filename . "\""); header("Cache-control: private"); $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); $objWriter->save("./assets/{$filename}"); header("location: " . SITE_LINK . "/assets/{$filename}"); unlink(SITE_LINK . "/assets/{$filename}"); }
/** * Format a recordset * * @param Garp_Model $model * @param array $rowset * @return string */ public function format(Garp_Model $model, array $rowset) { $phpexcel = new PHPExcel(); PHPExcel_Cell::setValueBinder(new PHPExcel_Cell_AdvancedValueBinder()); // set metadata $props = $phpexcel->getProperties(); if (Garp_Auth::getInstance()->isLoggedIn()) { $userData = Garp_Auth::getInstance()->getUserData(); $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); if ($bootstrap) { $view = $bootstrap->getResource('view'); $userName = $view->fullName($userData); $props->setCreator($userName)->setLastModifiedBy($userName); } } $props->setTitle('Garp content export – ' . $model->getName()); if (count($rowset)) { $this->_addContent($phpexcel, $model, $rowset); } /** * Hm, PHPExcel seems to only be able to write to a file (instead of returning * an XLS binary string). Therefore, we save a temporary file, read its contents * and return those, after which we unlink the temp file. */ $tmpFileName = APPLICATION_PATH . '/data/logs/tmp.xls'; $writer = PHPExcel_IOFactory::createWriter($phpexcel, 'Excel5'); $writer->save($tmpFileName); $contents = file_get_contents($tmpFileName); unlink($tmpFileName); return $contents; }
function export() { $model = M("Material"); $model = M("Material"); $map = $this->_search(); if (method_exists($this, '_filter')) { $this->_filter($map); } $list = $model->where($map)->select(); //导入thinkphp第三方类库 Vendor('Excel.PHPExcel'); $inputFileName = C("SAVE_PATH") . "templete/material.xlsx"; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $objPHPExcel->getProperties()->setCreator("小薇")->setLastModifiedBy("小薇")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file"); // Add some data $i = 1; //dump($list); foreach ($list as $val) { $i++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$i}", $val["mat_no"])->setCellValue("B{$i}", $val["name"])->setCellValue("C{$i}", $val["spec"])->setCellValue("D{$i}", $val["unit"])->setCellValue("E{$i}", $val["class"])->setCellValue("F{$i}", $val["buy_price"])->setCellValue("G{$i}", $val["sell_price"])->setCellValue("H{$i}", $val["init_qty"])->setCellValue("I{$i}", $val["min_qty"])->setCellValue("J{$i}", $val["max_qty"])->setCellValue("K{$i}", $val["remark"]); } // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('Material'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $file_name . '"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; }
function dictionnaryExportAction() { $this->disableLayout(); $this->disableView(); $select = $this->_db->select(); $select->from('Static_Texts')->order('ST_LangID'); $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', "Identifier"); $objPHPExcel->getActiveSheet()->setCellValue('B1', "LangID"); $objPHPExcel->getActiveSheet()->setCellValue('C1', "Value"); $objPHPExcel->getActiveSheet()->setCellValue('D1', "Type"); $items = $this->_db->fetchAll($select); $item_count = count($items); for ($i = 0; $i < $item_count; $i++) { $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $items[$i]['ST_Identifier']); $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $items[$i]['ST_LangID']); $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $items[$i]['ST_Value']); $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $items[$i]['ST_Type']); } header("Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header("Content-Disposition: attachment;filename=dictionnary.xlsx"); // output the file $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); }
function export($list, $params = array()) { if (PHP_SAPI == 'cli') { die('This example should only be run from a Web Browser'); } require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php'; $excel = new PHPExcel(); $excel->getProperties()->setCreator("人人商城")->setLastModifiedBy("人人商城")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("report file"); $sheet = $excel->setActiveSheetIndex(0); $rownum = 1; foreach ($params['columns'] as $key => $column) { $sheet->setCellValue($this->column($key, $rownum), $column['title']); if (!empty($column['width'])) { $sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']); } } $rownum++; foreach ($list as $row) { $len = count($row); for ($i = 0; $i < $len; $i++) { $value = $row[$params['columns'][$i]['field']]; $sheet->setCellValue($this->column($i, $rownum), $value); } $rownum++; } $excel->getActiveSheet()->setTitle($params['title']); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $params['title'] . '-' . date('Y-m-d H:i', time()) . '.xlsx"'); header('Cache-Control: max-age=0'); $writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007'); $writer->save('php://output'); exit; }
public function export() { $IBlockId = $this->GetIdOfTheList($_POST['list']); $IBlockCode = $this->GetCodeOfTheList($_POST['list']); $arIBlockElements = $this->getArrINlockElements($IBlockId); array_unshift($arIBlockElements, array_keys($arIBlockElements[0])); $phpexcel = new \PHPExcel(); /* Каждый раз делаем активной 1-ю страницу и получаем её, потом записываем в неё данные */ $page = $phpexcel->setActiveSheetIndex(0); //Массив с заглавными буквами латинского алфавита $letters = $this::getLetters(); $cellNumber = 1; foreach ($arIBlockElements as $arItem) { $numLitter = 0; foreach ($arItem as $item) { $page->setCellValue($letters[$numLitter] . $cellNumber, $item); $page->getStyle($letters[$numLitter] . $cellNumber)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $page->getStyle($letters[$numLitter] . '1')->getFont()->setBold(true); $page->getColumnDimension($letters[$numLitter])->setAutoSize(true); $numLitter++; } $cellNumber++; } $page->setTitle($IBlockCode); $objWriter = \PHPExcel_IOFactory::createWriter($phpexcel, 'Excel2007'); $objWriter->save('DBExport.xlsx'); header("Location: DBExport.xlsx"); }
/** * Excelにデータを出力し、ダウンロードする */ public function generate() { $excel = new PHPExcel(); $excel->setActiveSheetIndex(0); $sheet = $excel->getActiveSheet(); $sheet->setTitle('課題管理表'); // ヘッダ設定 foreach (self::$header as $key => $val) { $sheet->setCellValueByColumnAndRow($key, 1, $val); } // データ設定 foreach ($this->data as $key => $issue) { $row = $key + 2; $sheet->setCellValueByColumnAndRow(0, $row, $issue['No']); $sheet->setCellValueByColumnAndRow(1, $row, $issue['Title']); $sheet->setCellValueByColumnAndRow(2, $row, $issue['Created']); $sheet->setCellValueByColumnAndRow(3, $row, $issue['Updated']); $sheet->setCellValueByColumnAndRow(4, $row, $issue['Assignee']); $sheet->setCellValueByColumnAndRow(5, $row, $issue['State']); $sheet->setCellValueByColumnAndRow(6, $row, $issue['Labels']); $sheet->setCellValueByColumnAndRow(7, $row, $issue['Milestone']); } $writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007'); $writer->save($this->path); // 出力 header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename=' . basename($this->path) . ';'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($this->path)); readfile($this->path); unlink($this->path); exit; }
public static function exportXLS($items) { include 'lib/core/lhform/PHPExcel.php'; $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; $cacheSettings = array('memoryCacheSize ' => '64MB'); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->getStyle('A1:AW1')->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->setTitle('Report'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Chats')); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Department name')); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Operator')); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Stars')); $attributes = array('virtual_chats_number', 'department_name', 'user', 'average_stars'); $i = 2; foreach ($items as $item) { foreach ($attributes as $key => $attr) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, (string) $item->{$attr}); } $i++; } $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); // We'll be outputting an excel file header('Content-type: application/vnd.ms-excel'); // It will be called file.xls header('Content-Disposition: attachment; filename="report.xlsx"'); // Write file to the browser $objWriter->save('php://output'); }
function exportToExcel($itemlessRecords) { //PHPEXCEL // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("DCL")->setLastModifiedBy("DCL")->setTitle("Office 2007 XLSX Document")->setSubject("Office 2007 XLSX Document")->setDescription("Office 2007 XLSX, generated using PHP.")->setKeywords("office 2007 openxml php")->setCategory("eContent Wish List Report"); // Add some data $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'eContent Wish List Report')->setCellValue('A3', 'ID')->setCellValue('B3', 'Title')->setCellValue('C3', 'Author')->setCellValue('D3', 'ISBN')->setCellValue('E3', 'ILS Id')->setCellValue('F3', 'Source')->setCellValue('G3', 'Wishlist Size'); $a = 4; //Loop Through The Report Data foreach ($itemlessRecords as $itemlessRecord) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $a, $itemlessRecord->id)->setCellValue('B' . $a, $itemlessRecord->title)->setCellValue('C' . $a, $itemlessRecord->author)->setCellValue('D' . $a, $itemlessRecord->isbn)->setCellValue('E' . $a, $itemlessRecord->ilsId)->setCellValue('F' . $a, $itemlessRecord->source)->setCellValue('G' . $a, $itemlessRecord->numWishList); $a++; } $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); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Wish List'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client's web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename=EContentWishListReport.xls'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; }
public function generate(array $fields, array $data, $fileName = 'excelDbDump') { $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setTitle("export")->setDescription("none"); $objPHPExcel->setActiveSheetIndex(0); // Field names in the first row $col = 0; foreach ($fields as $field) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field); $col++; } // Fetching the table data $row = 2; foreach ($data as $data) { $col = 0; foreach ($fields as $field) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $data->{$field}); $col++; } $row++; } $objPHPExcel->setActiveSheetIndex(0); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); // Sending headers to force the user to download the file header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $fileName . '_' . date('d-m-y') . '.xls"'); header('Cache-Control: max-age=0'); $objWriter->save('php://output'); }