PHP PHPExcel Code Examples

This page contains top rated real world PHP examples of PHPExcel extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: Excel.php Project: ChenXL581X/distributedcourse
0
 public function exportExcel($input = array(), $excelName)
 {
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->setActiveSheetIndex(0);
     //将数组中的数据赋值给表
     foreach ($input as $keyRow => $Row) {
         foreach ($Row as $keyCol => $value) {
             // $value = iconv('gb2312', 'utf-8', $value);
             $objPHPExcel->getActiveSheet()->setCellValue(chr(ord('A') + $keyCol) . ($keyRow + '1'), $value);
         }
     }
     $ua = $_SERVER["HTTP_USER_AGENT"];
     $datetime = date('Y-m-d', time());
     if (preg_match("/MSIE/", $ua)) {
         $excelName = urlencode($excelName);
         //IE浏览器可以出现的问题
     }
     // excel导出
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="' . $excelName . '.xlsx"');
     header('Cache-Control: max-age=0');
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save('php://output');
     return ture;
 }
Example #2
Show file File: Serialized.php Project: sensorsix/app
0
 /**
  * Save PHPExcel to file
  *
  * @param 	string 		$pFileName
  * @throws 	Exception
  */
 public function save($pFilename = null)
 {
     if (!is_null($this->_spreadSheet)) {
         // Garbage collect...
         foreach ($this->_spreadSheet->getAllSheets() as $sheet) {
             $sheet->garbageCollect();
         }
         // Create new ZIP file and open it for writing
         $objZip = new ZipArchive();
         // Try opening the ZIP file
         if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
             if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
                 throw new Exception("Could not open " . $pFilename . " for writing.");
             }
         }
         // Add media
         $sheetCount = $this->_spreadSheet->getSheetCount();
         for ($i = 0; $i < $sheetCount; ++$i) {
             for ($j = 0; $j < $this->_spreadSheet->getSheet($i)->getDrawingCollection()->count(); ++$j) {
                 if ($this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcel_Worksheet_BaseDrawing) {
                     $imgTemp = $this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j);
                     $objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
                 }
             }
         }
         // Add phpexcel.xml to the document, which represents a PHP serialized PHPExcel object
         $objZip->addFromString('phpexcel.xml', $this->_writeSerialized($this->_spreadSheet, $pFilename));
         // Close file
         if ($objZip->close() === false) {
             throw new Exception("Could not close zip file {$pFilename}.");
         }
     } else {
         throw new Exception("PHPExcel object unassigned.");
     }
 }
Example #3
Show file File: CDBExport.php Project: AlistairGray/test-work
0
 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");
 }
Example #4
Show file File: lhsurveyexporter.php Project: Adeelgill/livehelperchat
0
 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');
 }
Example #5
Show file File: SellingModel.php Project: sov-20-07/billing
0
 public static function export($author)
 {
     $sql = 'SELECT * FROM {{iusers}} WHERE author=' . $author . ' ORDER BY code';
     $list = DB::getAll($sql);
     header('Content-Type: text/html; charset=utf-8');
     header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Cache-Control: post-check=0, pre-check=0', FALSE);
     header('Pragma: no-cache');
     header('Content-transfer-encoding: binary');
     header('Content-Disposition: attachment; filename=export.xls');
     header('Content-Type: application/octet-stream');
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->getProperties()->setCreator("")->setLastModifiedBy("")->setTitle("Office 2007 XLSX")->setSubject("Office 2007 XLSX")->setDescription("Document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("GBROS file");
     $sheet = $objPHPExcel->setActiveSheetIndex(0);
     $sheet->setCellValue('A1', 'ID');
     $sheet->setCellValue('B1', 'Имя');
     $sheet->setCellValue('C1', 'Баланс, руб.');
     $sheet->getColumnDimension('A')->setAutoSize(true);
     $sheet->getColumnDimension('B')->setAutoSize(true);
     $sheet->getColumnDimension('C')->setAutoSize(true);
     foreach ($list as $i => $item) {
         $sheet->setCellValue('A' . ($i + 2), $item['code']);
         $sheet->setCellValue('B' . ($i + 2), $item['name']);
         $sheet->setCellValue('C' . ($i + 2), $item['balance']);
         $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 1))->getAlignment()->setWrapText(true);
         $objPHPExcel->getActiveSheet()->getStyle('B' . ($i + 1))->getAlignment()->setWrapText(true);
         $objPHPExcel->getActiveSheet()->getStyle('C' . ($i + 1))->getAlignment()->setWrapText(true);
     }
     $objPHPExcel->getActiveSheet()->setTitle('Лист 1');
     $objPHPExcel->setActiveSheetIndex(0);
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save('php://output');
 }
Example #6
Show file File: kexport.php Project: kaantunc/MYK-BOR
0
function databaseToExcel($tableName, $firmId, $examId, $dir)
{
    $filename = "sinav_" . $firmId . "_" . $examId . ".xls";
    $db =& JFactory::getDBO();
    $query = "SELECT * FROM " . $tableName . " WHERE firmaId = " . $firmId . " AND sinavId = " . $examId;
    $db->setQuery($query);
    $data = $db->loadRowList();
    $tableFields = getTableFields($tableName);
    $columnNumber = getNumColumns($tableName);
    $phpExcel = new PHPExcel();
    //Configure the sheet
    $sheet = $phpExcel->getActiveSheet();
    $sheet->setTitle("jos_deneme");
    //Header
    for ($i = 3; $i < $columnNumber; $i++) {
        $value = $tableFields[$i];
        $sheet->setCellValueByColumnAndRow($i - 3, 1, $value);
    }
    //Data
    $row = 2;
    foreach ($data as $rows) {
        $column = 0;
        for ($i = 3; $i < $columnNumber; $i++) {
            $sheet->setCellValueByColumnAndRow($column, $row, $rows[$i]);
            $column++;
        }
        $row++;
    }
    $writer = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel5');
    $writer->save($dir . $filename);
    $redirect = JURI::base() . $dir . $filename;
    header('Location: ' . $redirect);
}
Example #7
Show file File: ExcelReportBillingWithdrawal.php Project: kbudylov/ttarget
0
 /**
  * Добавляет таблицу со списком
  *
  * @param PHPExcel $objPHPExcel
  * @param array $reportData
  */
 protected function addDataTable(PHPExcel $objPHPExcel, array $reportData)
 {
     $activeSheet = $objPHPExcel->getActiveSheet();
     $rowc = 11;
     foreach ($reportData['rows'] as $row) {
         $activeSheet->setCellValue('A' . $rowc, $row['number'])->setCellValue('B' . $rowc, date('d.m.Y', strtotime($row['issuing_date'])))->setCellValue('C' . $rowc, $row['paid_date'] ? date('d.m.Y', strtotime($row['paid_date'])) : '')->setCellValue('D' . $rowc, $row['platform_name'])->setCellValue('E' . $rowc, $row['debit'])->setCellValue('F' . $rowc, $row['sum'])->setCellValue('G' . $rowc, $row['is_vat'] ? Yii::app()->params->VAT / 100 : 0)->setCellValue('H' . $rowc, $row['sum_with_vat'])->setCellValue('I' . $rowc, $row['is_paid'] ? 'оплачен' : 'не оплачен')->setCellValue('J' . $rowc, $row['is_active'] ? 'активна' : 'неактивна');
         $activeSheet->getStyle('I' . $rowc)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $row['is_paid'] ? 'eaf1dd' : 'f2dddc')));
         $activeSheet->getStyle('J' . $rowc)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $row['is_active'] ? 'eaf1dd' : 'f2dddc')));
         if ($row['billing_details_type'] == null) {
             $activeSheet->setCellValue('K' . $rowc, 'нет данных');
             $activeSheet->getStyle('K' . $rowc)->getFont()->getColor()->setRGB('bfbfbf');
         } else {
             $activeSheet->setCellValue('K' . $rowc, $row['billing_details_type'] . ': ' . $row['billing_details_text']);
         }
         ++$rowc;
     }
     $this->addTableTotal($activeSheet, $reportData, $rowc);
     $this->formatTable($activeSheet, 'A', 10, 'K', $rowc, array('headerRowHeight' => 27));
     $activeSheet->getStyle('E11:G' . $rowc)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
     $activeSheet->getStyle('G11:F' . $rowc)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
     $activeSheet->getColumnDimension('A')->setWidth(10.71 * 1.05);
     $activeSheet->getColumnDimension('B')->setWidth(10.71 * 1.05);
     $activeSheet->getColumnDimension('C')->setWidth(10.71 * 1.05);
     $activeSheet->getColumnDimension('D')->setWidth(13.29 * 1.05);
     $activeSheet->getColumnDimension('E')->setWidth(14.71 * 1.05);
     $activeSheet->getColumnDimension('F')->setWidth(14.43 * 1.05);
     $activeSheet->getColumnDimension('G')->setWidth(13.71 * 1.05);
     $activeSheet->getColumnDimension('H')->setWidth(13.71 * 1.05);
     $activeSheet->getColumnDimension('I')->setWidth(16.14 * 1.05);
     $activeSheet->getColumnDimension('J')->setWidth(19.57 * 1.05);
     $activeSheet->getColumnDimension('K')->setWidth(35.71 * 1.05);
 }
Example #8
Show file File: Order.php Project: tigron/skeleton-package-stock
0
 /**
  * Export
  *
  * @access public
  */
 public function export()
 {
     $excel = new \PHPExcel();
     $worksheet = $excel->getActiveSheet();
     $row = 1;
     $worksheet->setCellValueByColumnAndRow(0, $row, 'Product');
     $worksheet->setCellValueByColumnAndRow(1, $row, 'price');
     $worksheet->setCellValueByColumnAndRow(2, $row, 'amount');
     $worksheet->setCellValueByColumnAndRow(3, $row, 'Total price');
     $excel->getActiveSheet()->getStyle('A1:D1')->getFont()->setBold(true);
     foreach ($this->get_purchase_order_items() as $purchase_order_item) {
         $row++;
         $worksheet->setCellValueByColumnAndRow(0, $row, $purchase_order_item->get_stock_object()->get_name());
         $worksheet->setCellValueByColumnAndRow(1, $row, $purchase_order_item->price);
         $worksheet->setCellValueByColumnAndRow(2, $row, $purchase_order_item->amount);
         $worksheet->setCellValueByColumnAndRow(3, $row, $purchase_order_item->price * $purchase_order_item->amount);
     }
     $row++;
     $worksheet->setCellValueByColumnAndRow(3, $row, $this->get_price());
     $excel->getActiveSheet()->getStyle($row . ':' . $row)->getFont()->setBold(true);
     $cellIterator = $worksheet->getRowIterator()->current()->getCellIterator();
     $cellIterator->setIterateOnlyExistingCells(true);
     /** @var PHPExcel_Cell $cell */
     foreach ($cellIterator as $cell) {
         $worksheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
     }
     $writer = new \PHPExcel_Writer_Excel2007($excel);
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="purchase_order_' . $this->id . '.xls"');
     header('Cache-Control: max-age=0');
     $writer->save('php://output');
     exit;
 }
Example #9
Show file File: GradeController.class.php Project: Hitwjm/dxms
0
 function exportExcel($expTitle, $expCellName, $expTableData)
 {
     $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);
     //文件名称
     $fileName = $_SESSION['account'] . date('_YmdHis');
     //or $xlsTitle 文件名称可根据自己情况设定
     $cellNum = count($expCellName);
     $dataNum = count($expTableData);
     vendor("PHPExcel.PHPExcel");
     $objPHPExcel = new \PHPExcel();
     $cellName = 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', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
     $objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');
     //合并单元格
     for ($i = 0; $i < $cellNum; $i++) {
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]);
     }
     for ($i = 0; $i < $dataNum; $i++) {
         for ($j = 0; $j < $cellNum; $j++) {
             $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 3), $expTableData[$i][$expCellName[$j][0]]);
         }
     }
     header('pragma:public');
     header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
     header("Content-Disposition:attachment;filename={$fileName}.xls");
     //attachment新窗口打印inline本窗口打印
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save('php://output');
     exit;
 }
Example #10
Show file File: ExportService.php Project: axelvnk/KunstmaanBundlesCMS
0
 /**
  * @param ExportableInterface $adminList
  *
  * @return \PHPExcel_Writer_Excel2007
  *
  * @throws \Exception
  * @throws \PHPExcel_Exception
  */
 public function createExcelSheet(ExportableInterface $adminList)
 {
     $objPHPExcel = new \PHPExcel();
     $objWorksheet = $objPHPExcel->getActiveSheet();
     $number = 1;
     $row = array();
     foreach ($adminList->getExportColumns() as $column) {
         $row[] = $column->getHeader();
     }
     $objWorksheet->fromArray($row, null, 'A' . $number++);
     $iterator = $adminList->getIterator();
     foreach ($iterator as $item) {
         if (array_key_exists(0, $item)) {
             $itemObject = $item[0];
         } else {
             $itemObject = $item;
         }
         $row = array();
         foreach ($adminList->getExportColumns() as $column) {
             $data = $adminList->getStringValue($itemObject, $column->getName());
             if (is_object($data)) {
                 if (!$this->renderer->exists($column->getTemplate())) {
                     throw new \Exception('No export template defined for ' . get_class($data));
                 }
                 $data = $this->renderer->render($column->getTemplate(), array('object' => $data));
             }
             $row[] = $data;
         }
         $objWorksheet->fromArray($row, null, 'A' . $number++);
     }
     $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
     return $objWriter;
 }
Example #11
Show file File: Excel.php Project: jackycgq/bzfshop
0
 /**
  * 把数组数据输出到 Excel 表格
  * 
  * @param array $dataArray 数据格式为 array(array(第一行数据), array(第二行数据), ...)
  * @param string $fileName 文件名,不带 xls 后缀,不带路径
  * @param string $filePath 输出文件的路径,如果为 null 表示输出到浏览器作为附件下载
  * @param int $maxCellWidth  最大单元格宽度限制
  * * */
 public static function dumpArrayToExel(array $dataArray, $fileName, $filePath = null, $maxCellWidth = null)
 {
     $objPHPExcel = new \PHPExcel();
     // 设置工作 sheet
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $activeSheet->fromArray($dataArray);
     // 调整列大小,防止数据挤到一起去了
     $maxColumnIndex = $activeSheet->getColumnDimension($activeSheet->getHighestColumn())->getColumnIndex();
     for ($columnIndex = 'A'; $columnIndex != $maxColumnIndex; $columnIndex++) {
         $activeSheet->getColumnDimension($columnIndex)->setAutoSize(true);
     }
     $activeSheet->calculateColumnWidths();
     if ($maxCellWidth > 0) {
         for ($columnIndex = 'A'; $columnIndex != $maxColumnIndex; $columnIndex++) {
             if ($activeSheet->getColumnDimension($columnIndex)->getWidth() > $maxCellWidth) {
                 $activeSheet->getColumnDimension($columnIndex)->setAutoSize(false);
                 $activeSheet->getColumnDimension($columnIndex)->setWidth($maxCellWidth);
                 $activeSheet->getStyle($columnIndex)->getAlignment()->setWrapText(true);
             }
         }
     }
     // 输出为 Excel5 格式
     $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
     if (empty($filePath)) {
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"');
         header('Cache-Control: max-age=0');
         $objWriter->save('php://output');
         //输出到浏览器
         return;
     }
     $objWriter->save($filePath . '/' . urlencode($fileName) . '.xls');
     //输出到文件
 }
Example #12
Show file File: Export.php Project: ahmatjan/Scene-Editor-for-mobile
0
 public function getTemplate()
 {
     try {
         Loader::import(PHPEXCEL_ROOT);
         $resultPHPExcel = new PHPExcel();
         $fieldAndTitle = $this->getFieldAndTitle();
         $n = 65;
         foreach ($fieldAndTitle as $val) {
             $coloum = chr($n) . '1';
             $resultPHPExcel->getActiveSheet()->setCellValue($coloum, $val);
             $n++;
         }
         $outputFileName = 'apply_data.xls';
         $xlsWriter = PHPExcel_IOFactory::createWriter($resultPHPExcel, 'Excel5');
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition:inline;filename="' . $outputFileName . '"');
         header("Content-Transfer-Encoding: binary");
         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: must-revalidate, post-check=0, pre-check=0");
         header("Pragma: no-cache");
         $xlsWriter->save("php://output");
     } catch (Exception $e) {
         echo $e->__toString();
     }
 }
Example #13
Show file File: ModReportsFunctions.php Project: racorrea/ReservaVideoconferencias
0
 public static function usersReport()
 {
     $conn = new Connect();
     $query = 'SELECT * FROM ' . self::DB_TBL_USUARIOS;
     $consult = $conn->prepare($query);
     $consult->execute();
     if ($consult->rowCount() > 0) {
         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
         header('Content-Disposition: attachment;filename="Reporte de usuarios.xlsx"');
         header('Cache-Control: max-age=0');
         $reportName = "Reporte de usuarios";
         $reportNameTitles = array("Id", "Cédula", "Nombres", "Apellidos", "Email", "Teléfono", "Extensión", "Usuario", "Contrasena", "Rol");
         $styleColumnsTitle = array('font' => array('name' => 'Arial', 'bold' => true));
         $generarReporteXLSX = new PHPExcel();
         $generarReporteXLSX->getProperties()->setCreator("VideoConferencias UTPL")->setLastModifiedBy("VideoConferencias UTPL")->setTitle("Reporte de usuarios")->setSubject("Reporte de usuarios")->setDescription("Reporte de usuarios")->setKeywords("Reporte de usuarios")->setCategory("Reportes");
         $generarReporteXLSX->setActiveSheetIndex(0)->mergeCells('A1:J1');
         $generarReporteXLSX->setActiveSheetIndex(0)->setCellValue('A1', $reportName)->setCellValue('A3', $reportNameTitles[0])->setCellValue('B3', $reportNameTitles[1])->setCellValue('C3', $reportNameTitles[2])->setCellValue('D3', $reportNameTitles[3])->setCellValue('E3', $reportNameTitles[4])->setCellValue('F3', $reportNameTitles[5])->setCellValue('G3', $reportNameTitles[6])->setCellValue('H3', $reportNameTitles[7])->setCellValue('I3', $reportNameTitles[8])->setCellValue('J3', $reportNameTitles[9]);
         $i = 4;
         while ($row = $consult->fetch()) {
             $generarReporteXLSX->setActiveSheetIndex(0)->setCellValue('A' . $i, $row['id'])->setCellValue('B' . $i, $row['cedula'])->setCellValue('C' . $i, $row['nombres'])->setCellValue('D' . $i, $row['apellidos'])->setCellValue('E' . $i, $row['email'])->setCellValue('F' . $i, $row['telefono'])->setCellValue('G' . $i, $row['telefono_ext'])->setCellValue('H' . $i, $row['usuario'])->setCellValue('I' . $i, $row['contrasena'])->setCellValue('J' . $i, $row['id_rol']);
             $i++;
         }
         $generarReporteXLSX->getActiveSheet()->getStyle('A3:J3')->applyFromArray($styleColumnsTitle);
         $generarReporteXLSX->getActiveSheet()->setTitle('Usuarios');
         $generarReporteXLSX->setActiveSheetIndex(0);
         $generarReporteXLSX->getActiveSheet(0)->freezePaneByColumnAndRow(0, 4);
         $objWriter = PHPExcel_IOFactory::createWriter($generarReporteXLSX, 'Excel2007');
         $objWriter->save('php://output');
         exit;
     }
 }
Example #14
Show file File: CrudGenerator.php Project: azizbekvahidov/foods
0
 public function actionTemplate()
 {
     Yii::import('ext.heart.excel.EHeartExcel', true);
     EHeartExcel::init();
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->getActiveSheet()->setCellValue('A1', 'No')->setCellValue('B1', 'ModelType')->setCellValue('C1', 'Model')->setCellValue('D1', 'Controller')->setCellValue('E1', 'ModelParent')->setCellValue('F1', 'ControllerParent');
     $modelPath = Yii::getPathOfAlias('application.models');
     $files = scandir($modelPath);
     $row = 2;
     foreach ($files as $file) {
         if (is_file($modelPath . '/' . $file) && CFileHelper::getExtension($file) === 'php' && !in_array($file, array('ContactForm.php', 'LoginForm.php', 'Admin.php', 'User.php'))) {
             $file_arr = explode(".", $file);
             $filename = $file_arr[0];
             $objPHPExcel->getActiveSheet()->setCellValue('A' . $row, $row - 1)->setCellValue('B' . $row, "1")->setCellValue('C' . $row, $filename)->setCellValue('D' . $row, 'test/' . $filename)->setCellValue('E' . $row, '-')->setCellValue('F' . $row, '-');
             $row++;
         }
     }
     // Redirect output to a client’s web browser (Excel2007)
     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     header('Content-Disposition: attachment;filename="models.xlsx"');
     header('Cache-Control: max-age=0');
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save('php://output');
     exit;
 }
Example #15
Show file File: Excel.php Project: alexislefebvre/symfony-kickstarter
0
 public function registrations($registrations = [])
 {
     ini_set('memory_limit', '1G');
     $headings = ['ID', 'Name', 'Email', 'Country', 'Items', 'Created'];
     $headingRow = 1;
     $highestHeadingCol = count($headings) - 1;
     $excel = new \PHPExcel();
     $sheet = $excel->getActiveSheet();
     $sheet->setTitle('Registrations')->getStyle($this->cellRange('A', $headingRow, $highestHeadingCol, $headingRow))->applyFromArray(self::$greyHeaderStyles);
     foreach ($headings as $col => $heading) {
         $sheet->setCellValueByColumnAndRow($col, $headingRow, $heading);
     }
     foreach (range('A', $sheet->getHighestColumn()) as $col) {
         $sheet->getColumnDimension($col)->setAutoSize(true);
     }
     foreach ([4] as $col) {
         $sheet->getColumnDimensionByColumn($col)->setAutoSize(false);
     }
     foreach ($registrations as $registration) {
         /** @var $registration Registration  */
         $row = $sheet->getHighestRow() + 1;
         $col = 0;
         $sheet->setCellValueByColumnAndRow($col++, $row, $registration->getId())->setCellValueByColumnAndRow($col++, $row, $registration->getName())->setCellValueByColumnAndRow($col++, $row, $registration->getEmail())->setCellValueByColumnAndRow($col++, $row, $registration->getCountry()->translate('en')->getTitle());
         $items = [];
         foreach ($registration->getItems() as $item) {
             $items[] = $item->getTitle();
         }
         $sheet->setCellValueByColumnAndRow($col++, $row, implode(', ', $items))->setCellValueByColumnAndRow($col++, $row, $registration->getCreatedAt()->format('d.m.Y H:i:s'));
     }
     return $this->retrieveContent($excel);
 }
Example #16
Show file File: gradebook_result.class.php Project: omaoibrahim/chamilo-lms
0
 /**
  * Exports the complete report as an XLS file
  * @return	boolean		False on error
  */
 public function exportCompleteReportXLS($data)
 {
     $filename = 'gradebook-results-' . api_get_local_time() . '.xls';
     $spreadsheet = new PHPExcel();
     $spreadsheet->setActiveSheetIndex(0);
     $worksheet = $spreadsheet->getActiveSheet();
     $line = 0;
     $column = 0;
     //skip the first column (row titles)
     //headers
     foreach ($data[0] as $header_col) {
         $worksheet->SetCellValueByColumnAndRow($line, $column, $header_col);
         $column++;
     }
     $line++;
     $cant_students = count($data[1]);
     for ($i = 0; $i < $cant_students; $i++) {
         $column = 0;
         foreach ($data[1][$i] as $col_name) {
             $worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($col_name)));
             $column++;
         }
         $line++;
     }
     $file = api_get_path(SYS_ARCHIVE_PATH) . api_replace_dangerous_char($filename);
     $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
     $writer->save($file);
     DocumentManager::file_send_for_download($file, true, $filename);
     exit;
 }
Example #17
Show file File: CExcel.php Project: fancyecommerce/yii2-fec
0
 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;
 }
Example #18
Show file File: OperationController.php Project: comaw/pars
0
 public function actionCsv($pars = 0)
 {
     if ($pars) {
         $model = Operation::find()->where("pars = :pars", [':pars' => (int) $pars])->orderBy("url asc")->all();
     } else {
         $model = Operation::find()->orderBy("url asc")->all();
     }
     include Yii::getAlias('@vendor/phpoffice/phpexcel/Classes/PHPExcel.php');
     include Yii::getAlias('@vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php');
     $objPHPExcel = new \PHPExcel();
     $objPHPExcel->getProperties()->setCreator("Php Shaman")->setLastModifiedBy("Php Shaman")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Data for yelp parsing")->setKeywords("office 2007 openxml php")->setCategory("Data for yelp parsing");
     // Add some data
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'name')->setCellValue('B1', 'categories')->setCellValue('C1', 'phone')->setCellValue('D1', 'state')->setCellValue('E1', 'city')->setCellValue('F1', 'address')->setCellValue('G1', 'postal')->setCellValue('H1', 'site')->setCellValue('I1', 'description');
     foreach ($model as $k => $o) {
         $cat = [];
         foreach ($o->categories as $c) {
             $cat[] = $c->name;
         }
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . ($k + 2), $o->name)->setCellValue('B' . ($k + 2), join(' | ', $cat))->setCellValue('C' . ($k + 2), $o->phone)->setCellValue('D' . ($k + 2), ParsSettings::getState($o->state))->setCellValue('E' . ($k + 2), $o->city)->setCellValue('F' . ($k + 2), $o->address)->setCellValue('G' . ($k + 2), $o->postal)->setCellValue('H' . ($k + 2), $o->site)->setCellValue('I' . ($k + 2), $o->description);
     }
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="pars.xls"');
     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');
     header('Pragma: public');
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save('php://output');
 }
Example #19
Show file File: Report.class.php Project: chriistiian/phpexcel-adodb-report-generator
0
 public function initialize($details)
 {
     $this->log("Loading PHPExcel");
     /** PHPExcel_Writer_Excel2007 */
     include 'PHPExcel/PHPExcel/Writer/Excel2007.php';
     /** PHPExcel_Writer_Excel5 - for 2003 and below */
     include 'PHPExcel/PHPExcel/Writer/Excel5.php';
     /** PHPExcel_HTML Writer*/
     include 'PHPExcel/PHPExcel/Writer/HTML.php';
     /** PHPExcel_PDF Writer */
     include 'PHPExcel/PHPExcel/IOFactory.php';
     /*Initialize format array*/
     $this->formats['xls'] = "Excel 2003";
     //$this->formats['xlsx'] = "Excel 2007";
     $this->formats['pdf'] = "Adobe PDF";
     $this->details = $details;
     $this->log("Loading details:" . "<ul>" . "<li>Creator: " . $details['creator'] . "</li>" . "<li>Title: " . $details['title'] . "</li>" . "<li>Format: " . $details['format'] . "</li>" . "<li>Filename: " . $details['fileName'] . "</li>" . "</ul>");
     // Create new PHPExcel object
     $objPHPExcel = new PHPExcel();
     $this->log("Creating report - " . $details['title']);
     // Set properties
     $this->log("Setting properties of report");
     $objPHPExcel->getProperties()->setCreator($details['creator'])->setLastModifiedBy($details['creator'])->setTitle($details['title'])->setSubject($details['title'] . " report")->setDescription($details['title'] . " report generated using PHPExcel and ADODB");
     $this->fileName = $details['fileName'];
     $this->format = $details['format'];
     $this->setPHPExcelObj($objPHPExcel);
 }
Example #20
Show file File: myexcel.php Project: eddy8/MT4-Member-System
0
 public function __construct()
 {
     require_once './include/phpexcel/PHPExcel.php';
     $objPHPExcel = new PHPExcel();
     $this->ins = $objPHPExcel;
     $objPHPExcel->getProperties()->setCreator('Eddy')->setLastModifiedBy("Eddy");
 }
Example #21
Show file File: Output.php Project: unionbt/hanpaimall
0
 public static function excel($data, $ext = 'xlsx', $filepath = TRUE)
 {
     $excel = new \PHPExcel();
     $excel->setActiveSheetIndex(0);
     $sheet = $excel->getActiveSheet();
     array_walk($data, function (&$v) {
         foreach ($v as $key => $value) {
             !is_scalar($value) && ($v[$key] = @strval($value));
         }
     });
     $sheet->fromArray($data);
     $filepath == TRUE && ($filepath = tempnam(storage_path('utils'), 'excel'));
     switch (strtolower($ext)) {
         case 'xlsx':
             $objWriter = new \PHPExcel_Writer_Excel2007($excel);
             break;
         case 'xls':
             $objWriter = new \PHPExcel_Writer_Excel5($excel);
             break;
         case 'csv':
             $objWriter = new \PHPExcel_Writer_CSV($excel);
             break;
         case 'pdf':
             $objWriter = new \PHPExcel_Writer_PDF($excel);
             break;
         default:
             # code...
             break;
     }
     $objWriter->save($filepath);
     //@unlink($filepath);
     return $filepath;
 }
Example #22
Show file File: Xls.php Project: vegas-cmf/exporter
0
 /**
  * {@inheritdoc}
  */
 public function output()
 {
     if ($this->config->getTemplate()) {
         return $this->getRenderedView();
     }
     $data = $this->config->getData();
     $xls = new \PHPExcel();
     $xls->setActiveSheetIndex(0);
     $sheet = $xls->getActiveSheet();
     $title = $this->config->getTitle();
     is_string($title) && $sheet->setTitle($title);
     $row = 1;
     $column = 'A';
     foreach ($this->config->getHeaders() as $header) {
         $sheet->setCellValue($column . $row, $header);
         ++$column;
     }
     ++$row;
     foreach ($data as $item) {
         $column = 'A';
         foreach ($this->getRawItem($item) as $value) {
             $sheet->setCellValue($column . $row, $value);
             ++$column;
         }
         ++$row;
     }
     return $this->getBuffer($xls);
 }
Example #23
Show file File: ExcelExport.php Project: norzechowicz/datagrid-bundle
0
 /**
  * @return ExportAbstract|\Symfony\Component\HttpFoundation\Response
  */
 public function setData()
 {
     $PHPExcel = new \PHPExcel();
     $dataGrid = $this->getDataGrid();
     $rowNum = 1;
     $colNum = 0;
     foreach ($dataGrid->getColumns() as $header) {
         $label = isset($this->translator) ? $this->translator->trans($header->getLabel(), array(), $header->getAttribute('translation_domain')) : $header->getLabel();
         $PHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colNum, $rowNum, $label);
         $colNum++;
     }
     $rowNum++;
     foreach ($dataGrid as $row) {
         $colNum = 0;
         foreach ($row as $cell) {
             $PHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colNum, $rowNum, (string) $cell->getValue());
             $colNum++;
         }
         $rowNum++;
     }
     $writer = $this->getWriter($PHPExcel);
     ob_start();
     $writer->save("php://output");
     $this->data = ob_get_clean();
     return $this->update();
 }
Example #24
Show file File: ExcelCreator.php Project: kung-fu/issue-excel-export
0
 /**
  * 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;
 }
Example #25
Show file File: ExcelReportBillingNotPaid.php Project: kbudylov/ttarget
0
 /**
  * Добавляет таблицу со списком
  *
  * @param PHPExcel $objPHPExcel
  * @param array $reportData
  */
 protected function addDataTable(PHPExcel $objPHPExcel, array $reportData)
 {
     $activeSheet = $objPHPExcel->getActiveSheet();
     $rowc = 11;
     foreach ($reportData['rows'] as $row) {
         $activeSheet->setCellValue('A' . $rowc, $row['platform_name'])->setCellValue('B' . $rowc, $row['clicks'])->setCellValue('C' . $rowc, $row['cost'])->setCellValue('D' . $rowc, $row['price'])->setCellValue('E' . $rowc, $row['is_vat'] ? Yii::app()->params->VAT / 100 : 0)->setCellValue('F' . $rowc, $row['price_with_vat'])->setCellValue('G' . $rowc, $row['debit'])->setCellValue('H' . $rowc, $row['debit_with_vat'])->setCellValue('I' . $rowc, $row['debit_vat'])->setCellValue('J' . $rowc, $row['is_active'] ? 'активна' : 'неактивна')->getStyle('J' . $rowc)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $row['is_active'] ? 'eaf1dd' : 'f2dddc'))));
         if (empty($row['billing_details_type'])) {
             $activeSheet->setCellValue('K' . $rowc, 'нет данных');
             $activeSheet->getStyle('K' . $rowc)->getFont()->getColor()->setRGB('bfbfbf');
         } else {
             $activeSheet->setCellValue('K' . $rowc, $row['billing_details_type'] . ': ' . $row['billing_details_text']);
         }
         ++$rowc;
     }
     $this->addTableTotal($activeSheet, $reportData, $rowc);
     $this->formatTable($activeSheet, 'A', 10, 'K', $rowc);
     $activeSheet->getStyle('C11:I' . $rowc)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
     $activeSheet->getStyle('E11:E' . $rowc)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
     $activeSheet->getColumnDimension('A')->setWidth(17.43 * 1.05);
     $activeSheet->getColumnDimension('B')->setWidth(13.29 * 1.05);
     $activeSheet->getColumnDimension('C')->setWidth(14.71 * 1.05);
     $activeSheet->getColumnDimension('D')->setWidth(14.71 * 1.05);
     $activeSheet->getColumnDimension('E')->setWidth(5.71 * 1.05);
     $activeSheet->getColumnDimension('F')->setWidth(13.71 * 1.05);
     $activeSheet->getColumnDimension('G')->setWidth(16.43 * 1.05);
     $activeSheet->getColumnDimension('H')->setWidth(14.29 * 1.05);
     $activeSheet->getColumnDimension('I')->setWidth(10.0 * 1.05);
     $activeSheet->getColumnDimension('J')->setWidth(16.14 * 1.05);
     $activeSheet->getColumnDimension('K')->setWidth(35.71 * 1.05);
 }
Example #26
Show file File: OpenDocument.php Project: alyayazilim/E-Ticaret-2015
0
 /**
  * Save PHPExcel to file
  *
  * @param  string  $pFilename
  * @throws PHPExcel_Writer_Exception
  */
 public function save($pFilename = null)
 {
     if (!$this->spreadSheet) {
         throw new PHPExcel_Writer_Exception('PHPExcel object unassigned.');
     }
     // garbage collect
     $this->spreadSheet->garbageCollect();
     // If $pFilename is php://output or php://stdout, make it a temporary file...
     $originalFilename = $pFilename;
     if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
         $pFilename = @tempnam(PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp');
         if ($pFilename == '') {
             $pFilename = $originalFilename;
         }
     }
     $objZip = $this->createZip($pFilename);
     $objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('meta_inf')->writeManifest());
     $objZip->addFromString('Thumbnails/thumbnail.png', $this->getWriterPart('thumbnails')->writeThumbnail());
     $objZip->addFromString('content.xml', $this->getWriterPart('content')->write());
     $objZip->addFromString('meta.xml', $this->getWriterPart('meta')->write());
     $objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->write());
     $objZip->addFromString('settings.xml', $this->getWriterPart('settings')->write());
     $objZip->addFromString('styles.xml', $this->getWriterPart('styles')->write());
     // Close file
     if ($objZip->close() === false) {
         throw new PHPExcel_Writer_Exception("Could not close zip file {$pFilename}.");
     }
     // If a temporary file was used, copy it to the correct file stream
     if ($originalFilename != $pFilename) {
         if (copy($pFilename, $originalFilename) === false) {
             throw new PHPExcel_Writer_Exception("Could not copy temporary zip file {$pFilename} to {$originalFilename}.");
         }
         @unlink($pFilename);
     }
 }
Example #27
Show file File: RelsRibbon.php Project: AlexandreSGV/siteentec
0
 /**
  * Write relationships for additional objects of custom UI (ribbon)
  *
  * @param 	PHPExcel	$pPHPExcel
  * @return 	string 		XML Output
  * @throws 	PHPExcel_Writer_Exception
  */
 public function writeRibbonRelationships(PHPExcel $pPHPExcel = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
     }
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // Relationships
     $objWriter->startElement('Relationships');
     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
     $localRels = $pPHPExcel->getRibbonBinObjects('names');
     if (is_array($localRels)) {
         foreach ($localRels as $aId => $aTarget) {
             $objWriter->startElement('Relationship');
             $objWriter->writeAttribute('Id', $aId);
             $objWriter->writeAttribute('Type', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image');
             $objWriter->writeAttribute('Target', $aTarget);
             $objWriter->endElement();
             //Relationship
         }
     }
     $objWriter->endElement();
     //Relationships
     // Return
     return $objWriter->getData();
 }
Example #28
Show file File: lib_xls.php Project: netcon-source/dotspotting
0
function xls_export_dots(&$rows, $more)
{
    loadpear("PHPExcel");
    $xls = new PHPExcel();
    $sheet = $xls->setActiveSheetIndex(0);
    $col_names = array_keys($rows[0]);
    $row = 1;
    $col = 0;
    foreach ($col_names as $c) {
        $sheet->setCellValueByColumnAndRow($col, $row, $c);
        $col++;
    }
    $row = 2;
    $col = 0;
    foreach ($rows as $_row) {
        foreach (array_values($_row) as $value) {
            $sheet->setCellValueByColumnAndRow($col, $row, $value);
            $col++;
        }
        $row++;
        $col = 0;
    }
    # Excel 2007 is just plain weird and confuses
    # both OpenOffice and Numbers.app
    # (20110201/straup)
    $writer = PHPExcel_IOFactory::createWriter($xls, 'Excel5');
    $writer->save($more['path']);
    return $more['path'];
}
Example #29
Show file File: excel.php Project: noikiy/mygit
0
 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;
 }
Example #30
Show file File: OutputExcel.php Project: perpel/ywfy
0
 public function output()
 {
     // Create new PHPExcel object
     $objPHPExcel = new \PHPExcel();
     $objSheet = $objPHPExcel->setActiveSheetIndex(0);
     $col = 0;
     $row = 1;
     if (isset($this->header)) {
         foreach ($this->header as $v) {
             $cell = \PHPExcel_Cell::stringFromColumnIndex($col) . $row;
             $objSheet->setCellValue($cell, $v);
             $col++;
         }
         $row++;
         $col = 0;
     }
     foreach ($this->content as $rowValue) {
         foreach ($rowValue as $_v) {
             $cell = \PHPExcel_Cell::stringFromColumnIndex($col) . $row;
             $objSheet->setCellValue($cell, $_v);
             $col++;
         }
         $row++;
         $col = 0;
     }
     // Rename worksheet
     $objPHPExcel->getActiveSheet()->setTitle($this->title);
     // Set active sheet index to the first sheet, so Excel opens this as the first sheet
     $objPHPExcel->setActiveSheetIndex(0);
     $this->browserExport($this->type, $this->filename);
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, $this->type);
     $objWriter->save('php://output');
 }