authenticode/spreadsheet

该软件包已被废弃,不再维护。未建议替代软件包。

在不更改文件任何其他属性的情况下替换Excel工作簿(.xlsx)中的工作表。与数据透视表配合使用最佳。

0.01 2019-07-12 14:35 UTC

This package is auto-updated.

Last update: 2021-07-15 14:16:04 UTC


README

在不更改文件任何其他属性的情况下替换Excel工作簿(.xlsx)中的工作表。

许可证

本程序是免费软件;有关详细信息,请参阅LICENSE。

详细信息

该库的主要目的是在不修改任何其他组件的情况下向现有Excel文件添加一个“数据表”。如果您有一个模板文件,例如包含“高级”功能(如图表、数据透视表、宏)的报告,并且您想在PHP应用程序中更改基本数据表,这将特别有用。

安装

使用composer将此存储库添加到您的依赖项中

{
	"require": {
		"authenticode/spreadsheet": "dev-master"
	}
}

示例

以下示例演示了如何使用Spreadsheet。以下内容也包含在“examples/”文件夹中的“example.php”中

<?php
        require_once('../vendor/autoload.php');
		// Create a new instance
        $dataTable = new Authenticode\Spreadsheet\Spreadsheet();
		// Specify the source file
        $in = 'spec.xlsx';
		// Specify the output file
        $out = 'test.xlsx';
		// Specify the data for the worksheet.
        $data = array(
                        array("Date" => new \DateTime('2014-01-01 13:00:00'), "Value 1" => 0, "Value 2" => 1),
                        array("Date" => new \DateTime('2014-01-02 14:00:00'), "Value 1" => 1, "Value 2" => 0),
                        array("Date" => new \DateTime('2014-01-03 15:00:00'), "Value 1" => 2, "Value 2" => -1),
                        array("Date" => new \DateTime('2014-01-04 16:00:00'), "Value 1" => 3, "Value 2" => -2),
                        array("Date" => new \DateTime('2014-01-05 17:00:00'), "Value 1" => 4, "Value 2" => -3),
        );
		// Attach the data table and copy the new xlsx file to the output file.
        $dataTable->showHeaders()->addRows($data)->attachToFile($in, $out);
?>

在此示例中,方法“attachToFile”创建一个新的Excel文件。如果您在Web应用程序中使用此库,您可能更喜欢“fillXLSX()”函数,该函数返回Excel文档的字符串表示形式。以下示例在Laravel应用程序中演示了这种情况

<?php
	class ReportController extends Controller {
		protected $dataTable;

	    public function __construct(\Authenticode\Spreadsheet\Spreadsheet $dataTable) {
	        $this->dataTable = $dataTable;
		}

		public function show($month) {
			$data = DB::select('select date,value1,value2 from reporting where MONTH(date) = ?', array($month));
			$path = storage_path() . '/reports/example.xlsx';
			$xlsx = $this->dataTable->showHeaders()->addRows($data)->fillXLSX($path);
			return Response::make($xlsx, 200, array(
				'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
				'Content-Disposition' => 'attachment; filename="report.xlsx"',
				'Content-Length' => strlen($xlsx)
			));
			// ...
		}
	}
?>

建议?

创建一个问题!