maraya/cake-php-excel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maraya/cake-php-excel

最新稳定版本:v1.1.2

Composer 安装命令:

composer require maraya/cake-php-excel

包简介

CakePHP excel generator using PHPExcel library

README 文档

README

A plugin to generate Excel files with CakePHP. Uses CakePHP view files to generate them (with PHPExcel_IOFactory class from PHPExcel).

Requirements

  • PHP 5.2.8
  • CakePHP 2.1+
  • PHPExcel
  • Composer

Installation

Add to your composer.json file (maraya/cake-php-excel)

"require": {
	"maraya/cake-php-excel": "1.1.*"
},
"config": {
	"vendor-dir": "Vendor/"
},
"extra": {
    "installer-paths": {
        "Plugin/CakePHPExcel": ["maraya/cake-php-excel"]
    }
}

And run

composer update

Usage

In app/Config/bootstrap.php add:

CakePlugin::load('CakePHPExcel', 
	array(
		'routes' => true
	)
);

Add the RequestHandler component to AppController, and map Excel extensions to the CakePHPExcel plugin

'RequestHandler' => array(
	'viewClassMap' => array(
		'xls' => 'CakeExcel.Excel',
		'xlsx' => 'CakeExcel.Excel'
	)
),

Create Layouts/xls/default.ctp (in this example the charset is UTF-8)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
	<?php echo $this->fetch('content'); ?>
</body>
</html>

Place the view templates in a xls subdir, for example: app/View/Reports/xls/clients.ctp

<h1>Title</h1>
<table width="100%" border="1">
	<tr>
		<td>col1</td>
		<td>col2</td>
		<td>col3</td>
	</tr>
	<tr>
		<td>val1</td>
		<td>val2</td>
		<td>val3</td>
	</tr>
</table>

And in your controller:

class ReportsController extends AppController {
    public function clients() {
		$this->excelConfig =  array(
			'filename' => 'clients.xlsx'
		);
	}
}

Call the URL

http://example.com/reports/clients.xlsx

If you want to download Excel5 format, change the URL extension from xlsx to xls.

Inside your view file you can write HTML code. Please see the PHPExcel documentation for a guide on how to use PHPExcel.

统计信息

  • 总下载量: 3.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-18