承接 vishwayon/phpstep 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

vishwayon/phpstep

Composer 安装命令:

composer require vishwayon/phpstep

包简介

PHP Spreadsheet Template Engine

README 文档

README

PHP Spreadsheet Template Engine

Thanks to PHPOffice/PhpSpreadsheet, we are able to generate various types of spreadsheets directly from php. PhpStep is an attempt to automate data populated spreadsheets using template tags.

In this project, we put together an existing xslx file containing some template attributes and a structured model or json data to output a ready to use spreadsheet with user readable data.

When to use PhpStep?

When you have a requirement to generate a Spreadsheet as output from PHP model objects then PhpStep can be very helpful. Typically you would write code to access data form model objects and use a package like PHPOffice/PhpSpreadsheet to render the output. The output spreadsheet reports might be designed by analysts to meet business needs and this requirement requires developers to codify it and go through a QA process. PhpStep can eliminate the process of having to push the requirement thorugh a SDLC cycle and gives a person with minimal coding skills the ability to generate these reports.

When to use StepService.php?

You can publish the StepService.php in any web server and call the page with json data, templated spreadsheet and the output file name. It would render the output file from within an independent process. For request parameters, refer the documentation of StepService.php

Dependencies

Installation and Usage

composer require vishwayon/phpstep "^0.1"

Or, use the git repository.

Supported Template Tags

  • $F{field_name} - A field/property in the class/data source
  • $Each{Iterator} - Any collection object/array implementing Iterator interface

Sample Code

First, create an sample.xlsx file with following structure:

A B
$F{message}
Country Population
$Each{stats}
$F{country} $F{population}

You can apply various formats to the cells and also create normal formulas.

require '../vendor/autoload.php';

$model = new \stdClass();
$model->message = 'Hello World!';
$model->stats = [
    ['country' => 'India', 'population' => 1300]
    ['country' => 'USA', 'population' => 330,
    ['country' => 'Russia', 'population' => 145
];

$reader = PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$ss = $reader->load("sample.xlsx");
$worksheet = $ss->getActiveSheet();

$re = new PhpStep\RenderWorksheet();
$re->applyData($worksheet, $model);

$writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($ss, 'Xlsx');
$writer->save('sampleResult.xlsx');

For complex methods, refer to test/TestRenderWorksheet.php and testData.xlsx

Limitations

  • Absolute formulas in the worksheet (e.g: $D$13) will not work. They would reference incorrect cells after rendering

License

PhpStep is licensed under MIT.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固