{"id":21850561,"url":"https://github.com/fastbolt/excel-writer","last_synced_at":"2025-04-14T15:03:26.370Z","repository":{"id":56981746,"uuid":"444789057","full_name":"fastbolt/excel-writer","owner":"fastbolt","description":"Excel-Writer component","archived":false,"fork":false,"pushed_at":"2024-10-02T09:31:07.000Z","size":189,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-09T11:48:39.142Z","etag":null,"topics":["data","excel","excel-export"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastbolt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-05T12:05:48.000Z","updated_at":"2024-10-02T09:30:22.000Z","dependencies_parsed_at":"2022-08-21T11:20:35.775Z","dependency_job_id":null,"html_url":"https://github.com/fastbolt/excel-writer","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbolt%2Fexcel-writer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbolt%2Fexcel-writer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbolt%2Fexcel-writer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastbolt%2Fexcel-writer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastbolt","download_url":"https://codeload.github.com/fastbolt/excel-writer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226837173,"owners_count":17689941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","excel","excel-export"],"created_at":"2024-11-28T00:18:12.392Z","updated_at":"2024-11-28T00:18:12.944Z","avatar_url":"https://github.com/fastbolt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Excel-Writer\nThis component is used for simple Excel-file generation in Symfony. You can pass either arrays of arrays, or arrays of entities to the generator class. If an entity references another entity as it's attribute, you will need to pass a callable to retrieve a specific value from that entity.\n\n## Installation\nThis package is available through Composer/Packagist:\n```php\n$ composer require fastbolt/excel-writer\n```\n\u003cbr/\u003e\n\n## Table size\nThe width of the table is set by the number of headers. The number of rows is set by the amount of data.\n\n## Columns\nThe order of columns is determined by the order of ColumnSetting instances given to ExcelGenerator::setColumns().\nYou need to define at least one column.\nThe order of the content will not be changed if an array is passed to setContent().\n\nIf you are passing objects to setContent(), you will need to provide the name of the method that returns\nthe values you want to display (like \"getName\").\n```php\n    $columns = [\n            new ColumnSetting('Name', ColumnSetting::FORMAT_STRING, 'getName'),\n            new ColumnSetting('ID', ColumnSetting::FORMAT_INTEGER, 'getId'),\n    ];\n\n    $generator = new ExcelGenerator();\n    $file = $generator\n                -\u003esetContent($data)\n                -\u003esetColumns($columns)\n                -\u003egenerateSpreadsheet('../var/temp/excelwriter');\n```\n\nYou can also pass closures instead of the getter.\n```php\n    $columns = [\n            new ColumnSetting('Loginname', ColumnSetting::FORMAT_STRING, static function($user) {\n               return $user-\u003egetLoginname();\n            })\n        ];\n```\n\n##Style\nCreate an instance of the TableStyle class and set styles for the header row and the content. Pass the TableStyle to the generator.\n```php\n    $headerStyle = [\n        'fill' =\u003e [\n            'fillType' =\u003e Fill::FILL_SOLID,\n            'color' =\u003e array('rgb' =\u003e 'FF9933')\n        ]\n    ];\n    $dataRowStyle = [\n        'fill' =\u003e array(\n            'fillType' =\u003e Fill::FILL_SOLID,\n            'color' =\u003e array('rgb' =\u003e '66FF66')\n        )\n    ];\n    \n    $style = new TableStyle();\n    $style\n        -\u003esetHeaderRowHeight(2)\n        -\u003esetHeaderStyle($headerStyle)\n        -\u003esetDataRowStyle($dataRowStyle);\n\n\n    $file = $generator\n        -\u003esetContent($data)\n        -\u003esetColumns($columns)\n        -\u003esetStyle($style)\n        -\u003egenerateSpreadsheet('../var/temp/filename');\n```\n\nTo apply styles to individual columns, you can either pass the style arrays as the 5th (header style) and 6th (data style) argument to the constructor, or use the setter of the ColumnSettings class.\n```php\n     $headerStyle = [\n            'fill' =\u003e [\n                'fillType' =\u003e Fill::FILL_SOLID,\n                'color' =\u003e array('rgb' =\u003e 'FF6622')\n            ]\n    ];\n    $dataStyle = [\n            'fill' =\u003e array(\n                'fillType' =\u003e Fill::FILL_SOLID,\n                'color' =\u003e array('rgb' =\u003e '22DD33')\n            )\n    ];\n   \n   //using the constructor\n   $column = new ColumnSetting(\"By Constructor\", ColumnSetting::FORMAT_STRING, '', 0, $headerStyle, $dataStyle);\n   \n    //using the setters \n    $column = new ColumnSetting(\"Styled Column\", ColumnSetting::FORMAT_STRING);\n    $column-\u003esetHeaderStyle($headerStyle)\n           -\u003esetDataStyle($dataStyle);\n```\n\n\n## Autofilter\nAutofilters can be set by calling the generator's setter method and passing a range:\n```php\n    $generator-\u003esetAutoFilterRange(\"A1:R14\");\n```\n\n\n## Style presets\nThe following styles are presets, but can be overwritten in the TableStyle class\n\n### header\n- borders: medium\n- vertical-alignment: center\n- horizontal-alignment: center\n- color: FF366092 (blue)\n\n## Merging Cells\nYou can merge cells by passing an array of coordinate ranges to the generator 'mergeCells'-method.\nThe content of the resulting cell will be centered. Calling the method multiple times will not overwrite previous merges.\n```php\n$generator-\u003emergeCells(['A1:B4'])\n          -\u003emergeCells(['P4:T4', 'S1:T1'])\n```\n\n## Hints\n* Floats have a preset decimal length of 2 (0.12), but that can be configured with the 4th parameter of the ColumnSetting constructor or its method setDecimalLength().\n* PHP and Excel have problems working with large numbers. Pass numbers with 16+ digits as strings to string columns to display them correctly.\n\n## Example usage\n\n### Using arrays\n```php\n    $data = [\n        [\n            $users[0],            //instance of a user entity\n            'Italy',\n            new DateTime('NOW')\n        ],\n        [\n            $users[1],           //instance of a user entity\n            'France',\n            new DateTime('NOW')\n        ]\n    ];\n\n    //define columns matching the order of the data\n    $columns = [\n        new ColumnSetting('Login', ColumnSetting::FORMAT_INTEGER, static function($user) {\n            return $user-\u003egetLoginname();\n        }),\n        new ColumnSetting('Country', ColumnSetting::FORMAT_STRING),\n        new ColumnSetting('Date', ColumnSetting::FORMAT_DATE)\n    ];\n\n    //generate\n    $generator = new ExcelGenerator();\n\n    $file = $generator\n        -\u003esetContent($data)\n        -\u003esetColumns($columns)\n        -\u003egenerateSpreadsheet('../var/temp/filename');\n```\n\n### Using objects\n\n```php\n    $repo = $this-\u003egetDoctrine()-\u003egetRepository(User::class);\n    $users = $repo-\u003efindBy(['client' =\u003e 5]);\n\n    //define columns matching the order of the data\n    $columns = [\n        new ColumnSetting('Login', ColumnSetting::FORMAT_INTEGER, 'getLoginName'),\n        new ColumnSetting('Country', ColumnSetting::FORMAT_STRING, static function($user) {\n            return $user-\u003egetCountry()-\u003egetName();\n        }),\n        new ColumnSetting('Created', ColumnSetting::FORMAT_DATE, 'getCreated')\n    ];\n\n    //generate\n    $generator = new ExcelGenerator();\n\n    $file = $generator\n        -\u003esetContent($users)\n        -\u003esetColumns($columns)\n        -\u003egenerateSpreadsheet('../var/temp/filename');\n```\n\n### Multiple worksheets\n\n```php\n    foreach ($userGroups as $userGroup) {\n        $excelGenerator\n                    -\u003esetTitle($userGroup-\u003egetName())\n                    -\u003esetContent($userGroup)\n                    -\u003esetColumns($columns)\n                    -\u003enextWorksheet();\n    }\n    $excelGenerator-\u003egenerateSpreadsheet('../var/temp/filename');\n```\n\n### Full example using objects and adding style\n```php\n    $repo  = $this-\u003egetDoctrine()-\u003egetRepository(User::class);\n    $users = $repo-\u003efindBy(['client' =\u003e 5]);\n\n    //define columns\n    $columns = [\n        new ColumnSetting('Login', ColumnSetting::FORMAT_INTEGER, 'getLoginName'),\n        new ColumnSetting('Country', ColumnSetting::FORMAT_STRING, static function($user) {\n            return $user-\u003egetCountry()-\u003egetName();\n        }),\n        new ColumnSetting('Created', ColumnSetting::FORMAT_DATE, 'getCreated'),\n        new ColumnSetting('Weight', ColumnSetting::FORMAT_FLOAT, 'getWeight', 2)\n    ];\n    \n    //set style\n    $headerStyle = [\n        'fill' =\u003e [\n            'fillType' =\u003e Fill::FILL_SOLID,\n            'color' =\u003e array('rgb' =\u003e 'FF9933')\n        ]\n    ];\n    $dataRowStyle = [\n        'fill' =\u003e array(\n            'fillType' =\u003e Fill::FILL_SOLID,\n            'color' =\u003e array('rgb' =\u003e '66FF66')\n        )\n    ];\n    \n    $style = new TableStyle();\n    $style\n        -\u003esetHeaderRowHeight(2)\n        -\u003esetHeaderStyle($headerStyle)\n        -\u003esetDataRowStyle($dataRowStyle);\n\n    //generate\n    $generator = new ExcelGenerator();\n\n    $file = $generator\n        -\u003esetContent($users)\n        -\u003esetColumns($columns)\n        -\u003esetStyle($style)\n        -\u003egenerateSpreadsheet('../var/temp/filename');\n\n    //download\n    $response = new BinaryFileResponse($file-\u003egetPathname());\n    $response-\u003esetContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);\n    return $response;\n```\n#   e x c e l - w r i t e r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastbolt%2Fexcel-writer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastbolt%2Fexcel-writer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastbolt%2Fexcel-writer/lists"}