tecno/wordbundle

这是一个Symfony2 Bundle,可以帮助您读取和写入Word文件(包括odt, rtf),得益于PHPWord库。

安装: 14

依赖: 0

建议者: 0

安全: 0

星星: 0

观察者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2014-05-30 21:00 UTC

This package is not auto-updated.

Last update: 2020-01-06 08:59:12 UTC


README

Build Status Total Downloads Latest Stable Version Latest Unstable Version

此bundle允许您创建一个易于修改的Excel对象。

版本2

这是全新的版本。与1.*版本有较大的不兼容性,但单元测试功能测试和新的工厂用法非常简单。

版本1.*

如果您已经安装了旧版本并且愿意使用它,您可以在标签v1.0.6中找到文档和文件,浏览代码

注意事项

CSV更快,所以如果您需要创建简单的xls文件,我建议您使用内置的csv函数:https://php.ac.cn/manual-lookup.php?pattern=csv&lang=en&scope=quickref

安装

1 将以下内容添加到composer.json中的require

    "require" : {
        "liuggio/excelbundle": "~2.0",
    }

2app/AppKernel.php中注册bundle

    $bundles = array(
        // ...
        new Liuggio\ExcelBundle\LiuggioExcelBundle(),
    );

TL;DR

  • 创建一个空对象
$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();
  • 从文件创建对象
$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject('file.xls');
  • 创建一个Excel5对象并将其写入文件
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
$writer->save('file.xls');
  • 创建一个Excel5对象并创建一个StreamedResponse
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
$response = $writer->createStreamedResponse($writer);

不仅'Excel5'

类型列表如下

  1. 'Excel5'
  2. 'Excel2007'
  3. 'Excel2003XML'
  4. 'OOCalc'
  5. 'SYLK'
  6. 'Gnumeric'
  7. 'HTML'
  8. 'CSV'

示例

模拟控制器

最好的起点是位于Tests/app/Controller/FakeController.php的模拟控制器,这是一个工作示例。

更多示例

您可以在官方PHPExcel存储库中找到很多示例https://github.com/PHPOffice/PHPExcel/tree/develop/Examples

懒惰开发者

namespace YOURNAME\YOURBUNDLE\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{

    public function indexAction($name)
    {
        // ask the service for a Excel5
       $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();

       $phpExcelObject->getProperties()->setCreator("liuggio")
           ->setLastModifiedBy("Giulio De Donato")
           ->setTitle("Office 2005 XLSX Test Document")
           ->setSubject("Office 2005 XLSX Test Document")
           ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
           ->setKeywords("office 2005 openxml php")
           ->setCategory("Test result file");
       $phpExcelObject->setActiveSheetIndex(0)
           ->setCellValue('A1', 'Hello')
           ->setCellValue('B2', 'world!');
       $phpExcelObject->getActiveSheet()->setTitle('Simple');
       // Set active sheet index to the first sheet, so Excel opens this as the first sheet
       $phpExcelObject->setActiveSheetIndex(0);

        // create the writer
        $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
        // create the response
        $response = $this->get('phpexcel')->createStreamedResponse($writer);
        // adding headers
        $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
        $response->headers->set('Content-Disposition', 'attachment;filename=stream-file.xls');
        $response->headers->set('Pragma', 'public');
        $response->headers->set('Cache-Control', 'maxage=1');

        return $response;        
    }
}

贡献者

贡献者列表https://github.com/liuggio/ExcelBundle/graphs/contributors

贡献

  1. 分支项目
  2. 克隆仓库
  3. 获取编码标准修复程序:wget http://cs.sensiolabs.org/get/php-cs-fixer.phar
  4. 在PullRequest之前,您应该使用以下命令运行编码标准修复程序:php php-cs-fixer.phar fix -v .