本文整理汇总了PHP中PHPExcel::addSheet方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel::addSheet方法的具体用法?PHP PHPExcel::addSheet怎么用?PHP PHPExcel::addSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel
的用法示例。
在下文中一共展示了PHPExcel::addSheet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mockWorkbook
/**
* @return \PHPExcel
*/
protected function mockWorkbook()
{
$workbook = new \PHPExcel();
$workbook->disconnectWorksheets();
$workbook->getProperties()->setTitle('mocked');
$sheet = new \PHPExcel_Worksheet($workbook);
$sheet->fromArray([['test', 'test', 'test'], ['test', 'test', 'test'], ['test', 'test', 'test'], ['test', 'test', 'test']]);
$workbook->addSheet($sheet);
$sheet = new \PHPExcel_Worksheet($workbook);
$sheet->fromArray([['test', 'test', 'test'], ['test', 'test', 'test'], ['test', 'test', 'test'], ['test', 'test', 'test']]);
$workbook->addSheet($sheet);
$workbook->setActiveSheetIndex(0);
return $workbook;
}
示例2: catalog_to_xlsx
function catalog_to_xlsx()
{
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Boy Gruv")->setLastModifiedBy("Boy Gruv")->setTitle("PHPExcel Document")->setSubject("PHPExcel Document")->setDescription("Document for PHPExcel, generated using PHP classes.")->setKeywords("office PHPExcel php")->setCategory("Result file");
// Заголовок страницы Categories
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'category_id')->setCellValue('B1', 'parent_id')->setCellValue('C1', 'name(en)')->setCellValue('D1', 'name(ru)')->setCellValue('E1', 'top')->setCellValue('F1', 'columns')->setCellValue('G1', 'sort_order')->setCellValue('H1', 'image_name')->setCellValue('I1', 'date_added')->setCellValue('J1', 'date_modified')->setCellValue('K1', 'seo_keyword')->setCellValue('L1', 'description(en)')->setCellValue('M1', 'description(ru)')->setCellValue('N1', 'meta_title(en)')->setCellValue('O1', 'meta_title(ru)')->setCellValue('P1', 'meta_description(en)')->setCellValue('Q1', 'meta_description(ru)')->setCellValue('R1', 'meta_keywords(en)')->setCellValue('S1', 'meta_keywords(ru)')->setCellValue('T1', 'store_ids')->setCellValue('U1', 'layout')->setCellValue('V1', 'status');
// Заполняем данные
$i = 2;
$arr = SQL_get_catalog();
for ($j = 0; $j < count($arr); $j++) {
$i = $j + 2;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $i, $arr[$j]["id_cat"] + 100)->setCellValue('B' . $i, $arr[$j]["parent_id"] + 100)->setCellValue('D' . $i, $arr[$j]["name"])->setCellValue('E' . $i, 'true')->setCellValue('F' . $i, '1')->setCellValue('G' . $i, '0')->setCellValue('I' . $i, date('Y-m-d H:i:s'))->setCellValue('J' . $i, date('Y-m-d H:i:s'))->setCellValue('K' . $i, '')->setCellValue('M' . $i, '')->setCellValue('T' . $i, '0')->setCellValue('V' . $i, 'true');
}
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Categories');
//Добавляем новую страницу
$MyWorkSheet = new PHPExcel_Worksheet($objPHPExcel, 'CategoryFilters');
$objPHPExcel->addSheet($MyWorkSheet, 1);
// Заголовок страницы CategoryFilters
$objPHPExcel->setActiveSheetIndex(1)->setCellValue('A1', 'category_id')->setCellValue('B1', 'filter_group')->setCellValue('C1', 'filter');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
$callStartTime = microtime(true);
$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__, PATHINFO_BASENAME)) , EOL;
$ret_str = date('H:i:s') . " File written to " . str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME));
return $ret_str;
}
示例3: _write
protected function _write(array $data){
//Umwandeln in numerischen Array
foreach($data AS $k => $dataEntry){
if(
$this->_charset != 'UTF-8'
){
//Umwandeln des Zeichensatzes
foreach($dataEntry AS $dataEntryK => $dataEntryV){
$dataEntry[$dataEntryK] = iconv('UTF-8', $this->_charset.'//TRANSLIT', $dataEntryV);
}
}
$data[$k] = array_values($dataEntry);
}
if(
$this->_useFirstRowAsTitles()
){
$data = array_merge(array($this->_titles), $data);
}
$this->_phpExcel = new PHPExcel();
$this->_phpExcel->addSheet();
$this->_phpExcel->getActiveSheet()->fromArray($data);
$this->_getWriter()->save($this->_file);
}
示例4: mockCell
/**
* @param string $text
*
* @return Cell
*/
protected function mockCell($text = 'text', $settings = false)
{
$workbook = new \PHPExcel();
$workbook->disconnectWorksheets();
$worksheet = new \PHPExcel_Worksheet($workbook);
$workbook->addSheet($worksheet);
$cell = $worksheet->setCellValue('A1', $pValue = $text, $returnCell = true);
$settings = $settings ?: new ParserSettings();
$cell = new Cell($cell, 1, $settings);
return $cell;
}
示例5: generateDocument
/**
* (non-PHPdoc)
* @see \scipper\Datatransfer\TransferService::generateEmptyDocument()
*/
public function generateDocument(Map $map)
{
if (!class_exists("PHPExcel")) {
throw new GenerationException("dependency 'PHPExcel' not found");
}
$excel = new \PHPExcel();
$excel->removeSheetByIndex(0);
$excel->getProperties()->setCreator($map->getCreator());
$excel->getProperties()->setTitle($map->getTitle());
$protectedStyle = new \PHPExcel_Style();
$protectedStyle->applyFromArray(array("fill" => array("type" => \PHPExcel_Style_Fill::FILL_SOLID, "color" => array("argb" => "55CCCCCC")), "borders" => array("bottom" => array("style" => \PHPExcel_Style_Border::BORDER_THIN), "right" => array("style" => \PHPExcel_Style_Border::BORDER_MEDIUM))));
$i = 0;
foreach ($map->getSheets() as $sheet) {
$active = $excel->addSheet(new \PHPExcel_Worksheet(NULL, $sheet->getTitle()), $i);
$active->getProtection()->setSheet(true);
$active->getStyle("A1:Z30")->getProtection()->setLocked(\PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
foreach ($sheet->getCells() as $cell) {
//Convert content to list format ist necessary
if ($cell->getType() == "select") {
$dataValidation = $active->getCell($cell->getCoord())->getDataValidation();
$dataValidation->setType(\PHPExcel_Cell_DataValidation::TYPE_LIST);
$dataValidation->setAllowBlank(false);
$dataValidation->setShowInputMessage(true);
$dataValidation->setShowDropDown(true);
$dataValidation->setFormula1($cell->getContent());
} else {
$active->setCellValue($cell->getCoord(), $cell->getValue());
}
//Add protection is necessary
if ($cell->isProtected()) {
$active->protectCells($cell->getCoord(), "123");
$active->setSharedStyle($protectedStyle, $cell->getCoord());
// } elseif(!$cell->isProtected() && $active->getProtection()->isProtectionEnabled()) {
// $active->unprotectCells($cell->getCoord());
}
$active->getColumnDimension($cell->getX())->setAutoSize(true);
if (!$cell->isVisible()) {
$active->getColumnDimension($cell->getX())->setVisible(false);
}
}
$i++;
}
$excel->setActiveSheetIndex(0);
$writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$filename = $this->documentRoot . $excel->getProperties()->getTitle() . ".xlsx";
$writer->save($filename);
return $filename;
}
示例6: prepararArchivo
/**
*
* @param PHPExcel_Worksheet $hoja
* @param int $pk representa el índice de la columna en el archivo de excel que está asociada con la llave primaria de la tabla
* @return string rerpesenta el nombre la ruta del archivo creado. Si no se pudo crear el archivo se regresa otra cosa :p
*/
function prepararArchivo($hoja, $pk = false, $incluirPrimeraFila = false)
{
$objetoExcel = new PHPExcel();
$hojaInsertar = $objetoExcel->getSheet(0);
$hojaInsertar->setTitle('Insertar');
if ($objetoExcel->getSheetCount() > 1) {
$hojaActualizar = $objetoExcel->getSheet(1);
$hojaActualizar->setTitle('Actualizar');
} else {
$hojaActualizar = new PHPExcel_Worksheet();
$hojaActualizar->setTitle('Actualizar');
$objetoExcel->addSheet($hojaActualizar);
}
$rango = $hoja->calculateWorksheetDataDimension();
if (!$incluirPrimeraFila) {
$rango[1] = '2';
}
$contenidoExcel = $hoja->rangeToArray($rango);
$datos = array();
$datos['insertar'] = array();
$datos['actualizar'] = array();
if ($pk) {
$db = new DbConnection();
$db->abrirConexion();
$llavePrimaria = $_SESSION['pk'];
foreach ($contenidoExcel as $fila) {
$existe = $db->existeRegistro($_SESSION['tabla'], $llavePrimaria, $fila[$pk]);
if ($existe) {
$datos['actualizar'][] = $fila;
} else {
$datos['insertar'][] = $fila;
}
}
$db->cerrarConexion();
} else {
foreach ($contenidoExcel as $fila) {
$datos['insertar'][] = $fila;
}
}
$hojaInsertar->fromArray($datos['insertar'], null, 'A1', true);
$hojaActualizar->fromArray($datos['actualizar'], null, 'A1', true);
$escritorExcel = PHPExcel_IOFactory::createWriter($objetoExcel, 'Excel2007');
$escritorExcel->save('excelTmp/tmp_import_upload.xlsx');
return 'excelTmp/tmp_import_upload.xlsx';
}
示例7: addAnalysis
private function addAnalysis(\PHPExcel $ea)
{
$ews2 = new \PHPExcel_Worksheet($ea, 'Summary');
$ea->addSheet($ews2, 0);
$ews2->setTitle('Summary');
$ews2->setCellValue('a1', 'Lakers 2013-2014 Season');
$style = array('font' => array('bold' => true, 'size' => 20), 'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_LEFT));
$ews2->mergeCells('a1:b1');
$ews2->getStyle('a1')->applyFromArray($style);
$ews2->getColumnDimension('a')->setAutoSize(true);
$ews2->setCellValue('a2', 'Win:');
$ews2->setCellValue('a3', 'Loss:');
$ews2->setCellValue('a4', '%:');
$ews2->setCellValue('b2', '=COUNTIF(Data!G2:G91, "W")-COUNTIF(Data!G2:G9, "W")');
$ews2->setCellValue('b3', '=COUNTIF(Data!G2:G91, "L")-COUNTIF(Data!G2:G9, "L")');
$ews2->setCellValue('b4', '=b2/(b2+b3)');
//$ews2->getStyle('b4')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
return $ews2;
}
示例8: excel_writer
function excel_writer($row_data_excel)
{
$objPHPEXCEL = new PHPExcel();
$row_len = count($row_data_excel);
$row_count = 0;
$myWorkSheet = new PHPExcel_WorkSheet($objPHPEXCEL, "班級");
$objPHPEXCEL->addSheet($myWorkSheet, 0);
$objPHPEXCEL->getSheet(0)->setCellValueByColumnAndRow(0, 1, "班級");
$objPHPEXCEL->getSheet(0)->getColumnDimension('A')->setWidth(12);
$column = 2;
while ($row_count < $row_len) {
$objPHPEXCEL->getSheet(0)->setCellValueByColumnAndRow(0, $column, $row_data_excel[$row_count]["class"]);
$row_count++;
$column++;
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPEXCEL, 'Excel5');
$objWriter->save("/var/www/sports/67/admin/excel/class.xls");
$objPHPEXCEL->disconnectWorksheets();
unset($objPHPEXCEL);
header("Location: http://dpo.nttu.edu.tw/sports/67/admin/excel/class.xls");
}
示例9: exportSheetExcel
/**
* 生成多个sheet的excel
*/
public function exportSheetExcel($listArr1 , $listArr2 , $headArr1 , $headArr2){
//if(!$listArr || !$headArr) return false;
set_time_limit(0);
// 关闭YII的自动加载功能,改用手动加载,否则会出错,PHPExcel有自己的自动加载功能
Yii::$enableIncludePath=false;
/*引入PHPExcel.php文件*/
Yii::import('application.extensions.PHPExcel.PHPExcel', 1);
$obj_phpexcel = new PHPExcel();
$obj_phpexcel->setActiveSheetIndex(0); //设置第一个工作表为活动工作表
$obj_phpexcel->getActiveSheet()->setTitle('orderhead'); //设置工作表名称
$objActSheet = $obj_phpexcel->getActiveSheet();
//设置字体
$objActSheet->getDefaultStyle()->getFont()->setName('微软雅黑');
//设置字体大小
$objActSheet->getDefaultStyle()->getFont()->setSize(9);
//设置自动行高
$objActSheet->getDefaultRowDimension()->setRowHeight(15);
$key = 0;
$keyArr = array();
foreach($headArr1 as $v){
$index = PHPExcel_Cell::stringFromColumnIndex($key);
$keyArr[] = $index;
//设置页头填充色
$objStyle = $objActSheet ->getStyle($index.'1');
$objFill = $objStyle->getFill();
$objFill->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objFill->getStartColor()->setARGB('#FFFF00');
//设置页头边框色
$objBorder = $objStyle->getBorders();
$objBorder->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objBorder->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objBorder->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objBorder->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
//设置自动列宽
$objActSheet->getColumnDimension($index)->setAutoSize(true);
//设置对其方式
$objAlign = $objStyle->getAlignment();
$objAlign->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objAlign->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$obj_phpexcel->setActiveSheetIndex(0)->setCellValue($index.'1' , $v);
$key++;
}
$keyWordArr = CDict::$title_key_word;
$keyWordArr2 = CDict::$title_hscode_word;
$key2 = 2;
foreach($listArr1 as $l_key =>$info){ //行写入
$key3 = 0;
foreach($info as $c_key=>$value){// 列写入
$span = $keyArr[$key3];
// $objStyle = $objActSheet ->getStyle($span.$key2);
// $objStyle->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
//设置单元格避免大数字科学计数显示
// if(in_array($c_key, array('ORDERCOMMITTIME','PAY_TIME','USER_ID','IDENTIFY_CODE'))){
// $objStyle = $objActSheet ->getStyle($span.$key2);
// $objStyle->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
// }
//$objActSheet->setCellValue($span.$key2, $value);
if(is_numeric($value) && $c_key != 'TRX_SERIAL_NO' && $c_key!='IDENTIFY_CODE' && $c_key!='USER_ID' && $c_key != 'GOODNO' && $c_key != 'HSCODE' && $c_key != 'RECEIVEZIPCODE' && $c_key != 'RECZIP' && $c_key != 'MERCHANTORDERID'){
$objStyle = $objActSheet ->getStyle($span.$key2);
if(strpos($value,'.')){
$objStyle->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
}else{
$objStyle->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
}
$objActSheet->setCellValue($span.$key2,$value);
}else{
$objActSheet->setCellValueExplicit($span.$key2,$value,PHPExcel_Cell_DataType::TYPE_STRING);
}
//$objActSheet->setCellValueExplicit($span.$key2,$value,PHPExcel_Cell_DataType::TYPE_STRING);
$key3++;
}
$key2++;
}
//创建第二个工作表
$newWorkSheet = new PHPExcel_Worksheet($obj_phpexcel, 'orderlist'); //创建一个工作表
$obj_phpexcel->addSheet($newWorkSheet); //插入工作表
$obj_phpexcel->setActiveSheetIndex(1); //切换到新创建的工作表
$objActSheet1 = $obj_phpexcel->getActiveSheet();
//设置字体
$objActSheet1->getDefaultStyle()->getFont()->setName('微软雅黑');
//设置字体大小
$objActSheet1->getDefaultStyle()->getFont()->setSize(9);
//设置自动行高
$objActSheet1->getDefaultRowDimension()->setRowHeight(15);
$key = 0;
$keyArr = array();
foreach($headArr2 as $v){
$index = PHPExcel_Cell::stringFromColumnIndex($key);
$keyArr[] = $index;
//设置页头填充色
$objStyle = $objActSheet1 ->getStyle($index.'1');
$objFill = $objStyle->getFill();
$objFill->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objFill->getStartColor()->setARGB('#FFFF00');
//.........这里部分代码省略.........
示例10: __construct
/**
* Class constructor
* @param PHPExcel_Worksheet $worksheet
*/
public function __construct(PHPExcel $spreadsheet, PHPExcel_Worksheet $worksheet = NULL)
{
if ($worksheet === NULL) {
$this->_worksheet = new PHPExcel_Worksheet($spreadsheet);
} else {
$this->_worksheet = $worksheet;
}
// Add worksheet to a spreadsheet
$spreadsheet->addSheet($this->_worksheet);
// Set worksheet title
if ($this->title !== NULL) {
$this->title($this->title);
}
}
示例11: __construct
/**
* Constructs one Moodle Worksheet.
*
* @param string $name The name of the file
* @param PHPExcel $workbook The internal Workbook object we are creating.
*/
public function __construct($name, PHPExcel $workbook)
{
// Replace any characters in the name that Excel cannot cope with.
$name = strtr($name, '[]*/\\?:', ' ');
// Shorten the title if necessary.
$name = core_text::substr($name, 0, 31);
if ($name === '') {
// Name is required!
$name = 'Sheet' . ($workbook->getSheetCount() + 1);
}
$this->worksheet = new PHPExcel_Worksheet($workbook, $name);
$this->worksheet->setPrintGridlines(false);
$workbook->addSheet($this->worksheet);
}
示例12: PHPExcel
$pr = $modelo->campania_001_Vodafon_one($in);
if (is_array($pr['datos'])) {
$ou = $modelo->campania_001_Vodafon_one_process($pr);
} else {
$ou = null;
}
}
// -------------------------------------------------------- TEST
// Utilidades::printr($in);
// Utilidades::printr($ou);
// -------------------------------------------------------- OUT
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Claudio Rodriguez Ore");
$objPHPExcel->getActiveSheet()->setTitle('Total');
$myWorkSheet = new PHPExcel_Worksheet($objPHPExcel, 'Supervisores');
$objPHPExcel->addSheet($myWorkSheet, 1);
$myWorkSheet = new PHPExcel_Worksheet($objPHPExcel, 'Asesores');
$objPHPExcel->addSheet($myWorkSheet, 2);
$border_style = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_HAIR, 'color' => array('argb' => '000000'))));
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(3))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(5))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(8))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(10))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(12))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(15))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(17))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(20))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(22))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(24))->setWidth(6);
$objPHPExcel->getActiveSheet()->getColumnDimension(c0(26))->setWidth(6);
示例13: downloadPHPExcelFile
//.........这里部分代码省略.........
foreach ($results = get_current_event_manual_entry_users_mysql() as $result) {
$activeSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->node_count);
$activeSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->user_name);
$rowNum++;
$colNum = 6;
}
$resultsCount = $initialRowNum + count($results);
$activeSheet->getStyle('G' . $initialRowNum . ':H' . $resultsCount)->applyFromArray($allBorders);
$activeSheet->getStyle('G' . $initialRowNum . ':H' . $initialRowNum)->applyFromArray($styleArray);
/**
* Count and names of Feed Importers
*/
$header = array('Events Expired', 'Feed Importer');
$colNum = 9;
foreach ($header as $value) {
$activeSheet->setCellValueByColumnAndRow($colNum, 4, $value);
$colNum++;
}
$rowNum = 5;
$colNum = 9;
foreach ($results = get_expired_event_feed_importers_name_mysql() as $result) {
$activeSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->node_count);
$activeSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->user_name);
$rowNum++;
$colNum = 9;
}
$resultsCount = 4 + count($results);
$activeSheet->getStyle('J4:K' . $resultsCount)->applyFromArray($allBorders);
$header = array('Events Current', 'Feed Importer');
$rowNum = $resultsCount + 2;
$initialRowNum = $rowNum;
$colNum = 9;
foreach ($header as $value) {
$activeSheet->setCellValueByColumnAndRow($colNum, $rowNum, $value);
$colNum++;
}
$rowNum = $initialRowNum + 1;
$colNum = 9;
foreach ($results = get_current_event_feed_importers_name_mysql() as $result) {
$activeSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->node_count);
$activeSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->user_name != '' ? $result->user_name : 'Anonymous');
$rowNum++;
$colNum = 9;
}
$resultsCount = $initialRowNum + count($results);
$activeSheet->getStyle('J' . $initialRowNum . ':K' . $resultsCount)->applyFromArray($allBorders);
$activeSheet->getStyle('J' . $initialRowNum . ':K' . $initialRowNum)->applyFromArray($styleArray);
/**
* Create a new worksheet called "Event Detail" $secondSheet
*/
$secondSheet = new PHPExcel_Worksheet($sheet, 'Event Detail');
$sheet->addSheet($secondSheet, 1);
$secondSheet = $sheet->getSheet(1);
$secondSheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$secondSheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$secondSheet->getStyle('A1:N1')->applyFromArray($styleArray);
// Loop to autoSize culumns width
for ($col = 'A'; $col <= 'M'; $col++) {
$secondSheet->getColumnDimension($col)->setAutoSize(true);
}
$secondSheet->getColumnDimension('N')->setWidth(60);
// Print column table labels
$header = array('Event Title', 'Detail Description', 'Event Start Date', 'Event End Date', 'Start Time', 'End Time', 'Address 1', 'Address 2', 'City', 'State', 'Zip Code', 'Country', 'Organization', 'Learn More URL');
foreach ($header as $key => $value) {
$secondSheet->setCellValueByColumnAndRow($key, 1, $value);
}
// Print cell values
$rowNum = 2;
$colNum = 0;
foreach ($results = current_events_detail_list_mysql() as $result) {
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->title);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, strip_tags($result->field_event_detail_desc_value));
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, date('M-d-Y', strtotime($result->field_event_date_value)));
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_date_value2 != null ? date('M-d-Y', strtotime($result->field_event_date_value2)) : $result->field_event_date_value2);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, date('H:i:s', strtotime($result->field_event_date_value)));
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, date('H:i:s', strtotime($result->field_event_date_value2)));
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_address_1_value);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_address_2_value);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_city_value);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_state_value);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_zip_value);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_country_value);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_program_org_tht_owns_prog_value);
$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $result->field_event_url_url);
//$secondSheet->setCellValueByColumnAndRow($colNum++, $rowNum, $GLOBALS['base_url'] . '/node/' . $result->nid);
$rowNum++;
$colNum = 0;
}
$resultsCount = 1 + count($results);
$secondSheet->getStyle('A1:N' . $resultsCount)->applyFromArray($allBorders);
/**
* redirect output to client browser
*/
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="event-summary.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($sheet, 'Excel5');
$objWriter->save('php://output');
return;
}
示例14: date
// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A4', 'Miscellaneous glyphs')->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
$objPHPExcel->getActiveSheet()->setCellValue('A8', "Hello\nWorld");
$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1);
$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);
// Rename worksheet
echo date('H:i:s'), " Rename worksheet", EOL;
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Clone worksheet
echo date('H:i:s'), " Clone worksheet", EOL;
$clonedSheet = clone $objPHPExcel->getActiveSheet();
$clonedSheet->setCellValue('A1', 'Goodbye')->setCellValue('A2', 'cruel')->setCellValue('C1', 'Goodbye')->setCellValue('C2', 'cruel');
// Rename cloned worksheet
echo date('H:i:s'), " Rename cloned worksheet", EOL;
$clonedSheet->setTitle('Simple Clone');
$objPHPExcel->addSheet($clonedSheet);
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
echo date('H:i:s'), " Write to Excel2007 format", EOL;
$callStartTime = microtime(true);
$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__, PATHINFO_BASENAME)), EOL;
echo 'Call time to write Workbook was ', sprintf('%.4f', $callTime), " seconds", EOL;
// Echo memory usage
echo date('H:i:s'), ' Current memory usage: ', memory_get_usage(true) / 1024 / 1024, " MB", EOL;
// Echo memory peak usage
echo date('H:i:s'), " Peak memory usage: ", memory_get_peak_usage(true) / 1024 / 1024, " MB", EOL;
示例15: reporte
function reporte($bls)
{
global $linkSrv, $linkDB, $linkUsr, $linkPass;
// -------------------------------------------------------------------------------
// ODBC
// El sistema se trata de conectar mediante ODBC nativo a la base de datos MscLink
// -------------------------------------------------------------------------------
$dsn = "Driver={SQL Server};Server={$linkSrv};Database={$linkDB};Integrated Security=SSPI;Persist Security Info=False;";
// Se realiza la conexón con los datos especificados anteriormente
$conn = odbc_connect($dsn, $linkUsr, $linkPass);
$conn2 = odbc_connect($dsn, $linkUsr, $linkPass);
// Incluir la libreria PHPExcel
require '../include/PHPExcel/PHPExcel.php';
// Reservar memoria en servidor PHP
// Si el archivo final tiene 5Mb, reservar 500Mb
// Por cada operación, phpExcel mapea en memoria la imagen del archivo y esto satura la mamoria
ini_set("memory_limit", "512M");
// Estilos Arreglo
$styleEnc = array('font' => array('bold' => true), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER), 'borders' => array('top' => array('style' => PHPExcel_Style_Border::BORDER_THIN)), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR, 'rotation' => 90, 'startcolor' => array('argb' => 'FFA0A0A0'), 'endcolor' => array('argb' => 'FFFFFFFF')));
$styleSombra = array('font' => array('bold' => true), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT), 'borders' => array('top' => array('style' => PHPExcel_Style_Border::BORDER_THIN)), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR, 'rotation' => 90, 'startcolor' => array('argb' => '80E9E07A'), 'endcolor' => array('argb' => 'FFFFFFFF')));
$styleTitulo = array('font' => array('bold' => true, 'size' => 14), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT));
$styleSubtitulo = array('font' => array('bold' => true, 'size' => 10), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT));
// ----------------------------
// Hoja 1
// Nota : No usar acentos!!!
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setTitle('Dep.Garantia');
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(8);
// HOJA 2
$workSheet2 = new PHPExcel_Worksheet($objPHPExcel, 'Demoras');
$objPHPExcel->addSheet($workSheet2, 1);
$workSheet2->getDefaultStyle()->getFont()->setSize(8);
$workSheet2->getDefaultStyle()->getFont()->setName('Arial');
// -----------------------------------------------
// ENCABEZADOS
// -----------------------------------------------
// Se crea el arreglo de hojas. Esto es como llevan el mismo encabezado en todas las hojas, solo es recorrer el index = hojas.
$arrHojas[] = 0;
//$arrHojas[]=1;
foreach ($arrHojas as $hoja) {
$objPHPExcel->setActiveSheetIndex($hoja);
// Se aplica estilo al encabezado
$objPHPExcel->getActiveSheet()->getStyle('A7:Q7')->applyFromArray($styleEnc);
// Encabezados
$headings = array('Concepto', 'Referencia', 'Nota', 'Nota1', 'Nota2', 'Nota3', 'Monto');
// Escribe los encabezados
$rowNumber = 7;
// Freeze pane so that the heading line won't scroll
$objPHPExcel->getActiveSheet()->freezePane('A8');
$col = 'A';
foreach ($headings as $heading) {
$objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading);
$col++;
}
// AutoFiltro
$objPHPExcel->getActiveSheet()->setAutoFilter('A7:G7');
// Auto Ajuste de Ancho en Columna
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
// Titulo
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'MEDITERRANEAN SHIPPING COMPANY MEXICO, S.A. DE C.V.')->getStyle('A1')->applyFromArray($styleTitulo);
// SUBTitulo
$objPHPExcel->getActiveSheet()->setCellValue('A2', '.');
$objPHPExcel->getActiveSheet()->getStyle('A2')->applyFromArray($styleSubtitulo);
$objPHPExcel->getActiveSheet()->setCellValue('A3', '.');
$objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray($styleSubtitulo);
$objPHPExcel->getActiveSheet()->setCellValue('A4', ".");
$objPHPExcel->getActiveSheet()->getStyle('A4')->applyFromArray($styleSubtitulo);
$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Depositos en Garantia MscLink');
$objPHPExcel->getActiveSheet()->getStyle('A5')->applyFromArray($styleSubtitulo);
}
// -------------------------
// Encabezado de la hoja 2
// -------------------------
$objPHPExcel->setActiveSheetIndex(1);
// Se aplica estilo al encabezado
$objPHPExcel->getActiveSheet()->getStyle('A7:S7')->applyFromArray($styleEnc);
// Encabezados
$headings = array('Bl', 'Contenedor', 'Concepto', 'Evento', 'Ev.Tiempo', 'EventoFin', 'EventoFin.Tiempo', 'POD', 'TMSCodeShp', 'Shipper', 'Inv.Company', 'DiasLibres', 'Invoice', 'Doc.Date', 'Amount', 'InvNum', 'TotInv', 'PaidInv', 'OustInv');
// Escribe los encabezados
$rowNumber = 7;
// Freeze pane so that the heading line won't scroll
$objPHPExcel->getActiveSheet()->freezePane('A8');
$col = 'A';
foreach ($headings as $heading) {
$objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $heading);
$col++;
}
// AutoFiltro
$objPHPExcel->getActiveSheet()->setAutoFilter('A7:S7');
// Auto Ajuste de Ancho en Columna
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
//.........这里部分代码省略.........