{"id":16272475,"url":"https://github.com/shuchkin/simplexlsxgen","last_synced_at":"2025-05-13T19:13:33.088Z","repository":{"id":37234922,"uuid":"265352456","full_name":"shuchkin/simplexlsxgen","owner":"shuchkin","description":"Export data to Excel. PHP XLSX generator","archived":false,"fork":false,"pushed_at":"2025-03-06T18:40:43.000Z","size":1578,"stargazers_count":1056,"open_issues_count":23,"forks_count":204,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-05-08T05:03:16.387Z","etag":null,"topics":["php","xlsx","xlsxwriter"],"latest_commit_sha":null,"homepage":"","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/shuchkin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-19T20:03:00.000Z","updated_at":"2025-05-06T20:20:46.000Z","dependencies_parsed_at":"2023-09-27T09:48:38.774Z","dependency_job_id":"c281058d-fed6-45d3-a18f-b49ed124ae00","html_url":"https://github.com/shuchkin/simplexlsxgen","commit_stats":{"total_commits":135,"total_committers":13,"mean_commits":"10.384615384615385","dds":0.2518518518518519,"last_synced_commit":"a44de02fe239e45cc86469b33509b542e73abeb8"},"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuchkin%2Fsimplexlsxgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuchkin%2Fsimplexlsxgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuchkin%2Fsimplexlsxgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuchkin%2Fsimplexlsxgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shuchkin","download_url":"https://codeload.github.com/shuchkin/simplexlsxgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253851592,"owners_count":21973770,"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":["php","xlsx","xlsxwriter"],"created_at":"2024-10-10T18:17:55.922Z","updated_at":"2025-05-13T19:13:33.069Z","avatar_url":"https://github.com/shuchkin.png","language":"PHP","funding_links":["https://opencollective.com/simplexlsx"],"categories":[],"sub_categories":[],"readme":"# SimpleXLSXGen\n[\u003cimg src=\"https://img.shields.io/github/license/shuchkin/simplexlsxgen\" /\u003e](https://github.com/shuchkin/simplexlsxgen/blob/master/license.md) [\u003cimg src=\"https://img.shields.io/github/stars/shuchkin/simplexlsxgen\" /\u003e](https://github.com/shuchkin/simplexlsxgen/stargazers) [\u003cimg src=\"https://img.shields.io/github/forks/shuchkin/simplexlsxgen\" /\u003e](https://github.com/shuchkin/simplexlsxgen/network) [\u003cimg src=\"https://img.shields.io/github/issues/shuchkin/simplexlsxgen\" /\u003e](https://github.com/shuchkin/simplexlsxgen/issues)\n\nExport data to Excel XLSX file. PHP XLSX generator. No external tools and libraries.  \n- XLSX reader [here](https://github.com/shuchkin/simplexlsx)\n- XLS reader [here](https://github.com/shuchkin/simplexls)\n- CSV reader/writer [here](https://github.com/shuchkin/simplecsv)\n\n**Sergey Shuchkin** \u003csergey.shuchkin@gmail.com\u003e 2020-2024\u003cbr/\u003e\n\n*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!* \n\n## Basic Usage\n```php\n$books = [\n    ['ISBN', 'title', 'author', 'publisher', 'ctry' ],\n    [618260307, 'The Hobbit', 'J. R. R. Tolkien', 'Houghton Mifflin', 'USA'],\n    [908606664, 'Slinky Malinki', 'Lynley Dodd', 'Mallinson Rendel', 'NZ']\n];\n$xlsx = Shuchkin\\SimpleXLSXGen::fromArray( $books );\n$xlsx-\u003esaveAs('books.xlsx'); // or downloadAs('books.xlsx') or $xlsx_content = (string) $xlsx \n```\n![XLSX screenshot](books.png)\n\n## Installation\nThe recommended way to install this library is [through Composer](https://getcomposer.org).\n[New to Composer?](https://getcomposer.org/doc/00-intro.md)\n\nThis will install the latest supported version:\n```bash\n$ composer require shuchkin/simplexlsxgen\n```\nor download class [here](https://github.com/shuchkin/simplexlsxgen/blob/master/src/SimpleXLSXGen.php)\n\n## Examples\nUse UTF-8 encoded strings.\n### Data types\n```php\n$data = [\n    ['Integer', 123],\n    ['Float', 12.35],\n    ['Percent', '12%'],\n    ['Currency $', '$500.67'],\n    ['Currency €', '200 €'],\n    ['Currency ₽', '1200.30 ₽'],\n    ['Currency (other)', '\u003cstyle nf=\"\u0026quot;£\u0026quot;#,##0.00\"\u003e500\u003c/style\u003e'],\n    ['Currency Float (other)', '\u003cstyle nf=\"#,##0.00\\ [$£-1];[Red]#,##0.00\\ [$£-1]\"\u003e500.250\u003c/style\u003e'],\n    ['Datetime', '2020-05-20 02:38:00'],\n    ['Date', '2020-05-20'],\n    ['Time', '02:38:00'],\n    ['Datetime PHP', new DateTime('2021-02-06 21:07:00')],\n    ['String', 'Very long UTF-8 string in autoresized column'],\n    ['Formula', '\u003cf v=\"135.35\"\u003eSUM(B1:B2)\u003c/f\u003e'],\n    ['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'],\n    ['Hyperlink + Anchor', '\u003ca href=\"https://github.com/shuchkin/simplexlsxgen\"\u003eSimpleXLSXGen\u003c/a\u003e'],\n    ['Internal link', '\u003ca href=\"sheet2!A1\"\u003eGo to second page\u003c/a\u003e'],\n    ['RAW string', \"\\0\" . '2020-10-04 16:02:00'],\n    ['Formatted RAW string', '\u003cb\u003e\u003ci\u003e\u003craw\u003e2024-07-28 16:02:00\u003c/raw\u003e\u003c/i\u003e\u003c/b\u003e'],\n];\nSimpleXLSXGen::fromArray($data)-\u003esaveAs('datatypes.xlsx');\n```\n![XLSX screenshot](datatypes.png)\n\n### Formatting\n```php\n$data = [\n    ['Normal', '12345.67'],\n    ['Bold', '\u003cb\u003e12345.67\u003c/b\u003e'],\n    ['Italic', '\u003ci\u003e12345.67\u003c/i\u003e'],\n    ['Underline', '\u003cu\u003e12345.67\u003c/u\u003e'],\n    ['Strike', '\u003cs\u003e12345.67\u003c/s\u003e'],\n    ['Bold + Italic', '\u003cb\u003e\u003ci\u003e12345.67\u003c/i\u003e\u003c/b\u003e'],\n    ['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'],\n    ['Italic + Hyperlink + Anchor', '\u003ci\u003e\u003ca href=\"https://github.com/shuchkin/simplexlsxgen\"\u003eSimpleXLSXGen\u003c/a\u003e\u003c/i\u003e'],\n    ['Green', '\u003cstyle color=\"#00FF00\"\u003e12345.67\u003c/style\u003e'],\n    ['Bold Red Text', '\u003cb\u003e\u003cstyle color=\"#FF0000\"\u003e12345.67\u003c/style\u003e\u003c/b\u003e'],\n    ['Size 32 Font', '\u003cstyle font-size=\"32\"\u003eBig Text\u003c/style\u003e'],\n    ['Blue Text and Yellow Fill', '\u003cstyle bgcolor=\"#FFFF00\" color=\"#0000FF\"\u003e12345.67\u003c/style\u003e'],\n    ['Border color', '\u003cstyle border=\"#000000\"\u003eBlack Thin Border\u003c/style\u003e'],\n    ['\u003ctop\u003eBorder style\u003c/top\u003e','\u003cstyle border=\"medium\"\u003e\u003cwraptext\u003enone, thin, medium, dashed, dotted, thick, double, hair, mediumDashed, dashDot,mediumDashDot, dashDotDot, mediumDashDotDot, slantDashDot\u003c/wraptext\u003e\u003c/style\u003e'],\n    ['Border sides', '\u003cstyle border=\"none dotted#0000FF medium#FF0000 double\"\u003eTop No + Right Dotted + Bottom medium + Left double\u003c/style\u003e'],\n    ['Left', '\u003cleft\u003e12345.67\u003c/left\u003e'],\n    ['Center', '\u003ccenter\u003e12345.67\u003c/center\u003e'],\n    ['Right', '\u003cright\u003eRight Text\u003c/right\u003e'],\n    ['Center + Bold', '\u003ccenter\u003e\u003cb\u003eName\u003c/b\u003e\u003c/center\u003e'],\n    ['Row height', '\u003cstyle height=\"50\"\u003eRow Height = 50\u003c/style\u003e'],\n    ['Top', '\u003cstyle height=\"50\"\u003e\u003ctop\u003eTop\u003c/top\u003e\u003c/style\u003e'],\n    ['Middle + Center', '\u003cstyle height=\"50\"\u003e\u003cmiddle\u003e\u003ccenter\u003eMiddle + Center\u003c/center\u003e\u003c/middle\u003e\u003c/style\u003e'],\n    ['Bottom + Right', '\u003cstyle height=\"50\"\u003e\u003cbottom\u003e\u003cright\u003eBottom + Right\u003c/right\u003e\u003c/bottom\u003e\u003c/style\u003e'],\n    ['\u003ccenter\u003eMERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS\u003c/center\u003e', null],\n    ['\u003ctop\u003eWord wrap\u003c/top\u003e', \"\u003cwraptext\u003eLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book\u003c/wraptext\u003e\"],\n    ['Linebreaks', \"Line 1\\nLine 2\\nLine 3\"]\n];\nSimpleXLSXGen::fromArray($data)\n    -\u003esetDefaultFont('Courier New')\n    -\u003esetDefaultFontSize(14)\n    -\u003esetColWidth(1, 35)\n    -\u003emergeCells('A20:B20')\n    -\u003esaveAs('styles_and_tags.xlsx');\n```\n![XLSX screenshot](styles.png)\n\n### RAW Strings\nPrefix #0 cell value (use double quotes) or use ::raw() method, or tag ```\u003craw\u003e```\n```php\n$PushkinDOB = '1799-07-06';\n$data = [\n    ['Datetime as raw string', \"\\0\".'2023-01-09 11:16:34'],\n    ['Date as raw string', \"\\0\".$PushkinDOB],\n    ['Disable type detection', \"\\0\".'+12345'],\n    ['Insert greater/less them simbols', SimpleXLSXGen::raw('20- short term: \u003c6 month')],\n    ['Formatted raw', '\u003cb\u003e\u003ccenter\u003e\u003craw\u003e+123456 \u0026lt;tag\u0026gt;\u003ctag2\u003e\u003c/raw\u003e\u003c/center\u003e\u003c/b\u003e'],\n];\nSimpleXLSXGen::fromArray($data)\n    -\u003esaveAs('test_rawstrings.xlsx');\n```\n### More examples\n```php\n// Fluid interface, output to browser for download\nShuchkin\\SimpleXLSXGen::fromArray( $books )-\u003edownloadAs('table.xlsx');\n\n// Fluid interface, multiple sheets\nShuchkin\\SimpleXLSXGen::fromArray( $books, 'My books' )-\u003eaddSheet( $books2 )-\u003edownload();\n\n// Alternative interface, sheet name, get xlsx content\n$xlsx_cache = (string) (new Shuchkin\\SimpleXLSXGen)-\u003eaddSheet( $books, 'Modern style');\n\n// Classic interface\nuse Shuchkin\\SimpleXLSXGen;\n$xlsx = new SimpleXLSXGen();\n$xlsx-\u003eaddSheet( $books, 'Catalog 2021' );\n$xlsx-\u003eaddSheet( $books2, 'Stephen King catalog');\n$xlsx-\u003edownloadAs('books_2021.xlsx');\nexit();\n\n// Empty book with title\n$xlsx = SimpleXLSX::create('My books');\n$xlsx-\u003eaddSheet( $books );\n$xlsx-\u003esave(); // ./My books.xlsx\n\n// Hyperlinks\n$xlsx = SimpleXLSX::fromArray([\n    ['internal link', '\u003ca href=\"\\'My books 2\\'!A1\"\u003eGo to second sheet\u003c/a\u003e'],\n    ['http', 'https://example.com/'], // autodetect\n    ['http + hash', 'https://en.wikipedia.org/wiki/Office_Open_XML#References'], // autodetect\n    ['external anchor', '\u003ca href=\"https://en.wikipedia.org/wiki/Office_Open_XML#References\"\u003eOpen XML\u003c/a\u003e'],\n    ['relative link', '\u003ca href=\"books.xlsx\"\u003ebooks\u003c/a\u003e'],\n    ['relative link + cell addr', '\u003ca href=\"..\\books.xlsx#\\'Sheet 2\\'!A1\"\u003elink to second sheet in other book\u003c/a\u003e'],\n    ['mailto', 'info@example.com'], // autodetect\n    ['mailto 2', '\u003ca href=\"mailto:info@example.com\"\u003ePlease email me\u003c/a\u003e'],\n])-\u003eaddSheet([['Second sheet']], 'My books 2')-\u003esaveAs('hyperlinks.xlsx');\n\n// Autofilter\n$xlsx-\u003eautoFilter('A1:B10');\n\n// Freeze rows and columns from top-left corner up to, but not including,\n// the row and column of the indicated cell\n$xlsx-\u003efreezePanes('B2'); // B1 - freeze first column, A2 - freeze top row\n\n// RTL mode\n// Column A is on the far right, Column B is one column left of Column A, and so on.\n// Also, information in cells is displayed in the Right to Left format.\n$xlsx-\u003erightToLeft();\n\n// Set Meta Data Files\n// this data in propertis Files and Info file in Office \n$xlsx-\u003esetAuthor('John Doe \u003cjohn@example.com\u003e')\n    -\u003esetCompany('JD LLC \u003cjd@mexample.com\u003e')\n    -\u003esetManager('Jane Doe \u003cjane@example.com\u003e')\n    -\u003esetLastModifiedBy(\"John Doe \u003cjohn@example.com\u003e\")\n    -\u003esetTitle('My Books')\n    -\u003esetSubject('My bookshelf')\n    -\u003esetKeywords('Tolkien,Rowling,Kipling')\n    -\u003esetDescription('Cool books worn by time')\n    -\u003esetCategory('Books')\n    -\u003esetLanguage('en-US')\n    -\u003esetApplication('Shuchkin\\SimpleXLSXGen')\n```\n### JS array to Excel (AJAX)\n```php\n\u003c?php // array2excel.php\nif (isset($_POST['array2excel'])) {\n    require __DIR__.'/simplexlsxgen/src/SimpleXLSXGen.php';\n    $data = json_decode($_POST['array2excel'], false);\n    \\Shuchkin\\SimpleXLSXGen::fromArray($data)-\u003edownloadAs('file.xlsx');\n    return;\n}\n?\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003ctitle\u003eJS array to Excel\u003c/title\u003e\n\u003c/head\u003e\n\u003cscript\u003e\n\nfunction array2excel() {\n    var books = [\n        [\"ISBN\", \"title\", \"author\", \"publisher\", \"ctry\"],\n        [618260307, \"The Hobbit\", \"J. R. R. Tolkien\", \"Houghton Mifflin\", \"USA\"],\n        [908606664, \"Slinky Malinki\", \"Lynley Dodd\", \"Mallinson Rendel\", \"NZ\"]\n    ];\n    var json = JSON.stringify(books);\n\n    var request = new XMLHttpRequest();\n\n    request.onload = function () {\n        if (this.status === 200) {\n            var file = new Blob([this.response], {type: this.getResponseHeader('Content-Type')});\n            var fileURL = URL.createObjectURL(file);\n            var filename = \"\", m;\n            var disposition = this.getResponseHeader('Content-Disposition');\n            if (disposition \u0026\u0026 (m = /\"([^\"]+)\"/.exec(disposition)) !== null) {\n                filename = m[1];\n            }\n            var a = document.createElement(\"a\");\n            if (typeof a.download === 'undefined') {\n                window.location = fileURL;\n            } else {\n                a.href = fileURL;\n                a.download = filename;\n                document.body.appendChild(a);\n                a.click();\n            }\n        } else {\n            alert(\"Error: \" + this.status + \"  \" + this.statusText);\n        }\n    }\n    \n    request.open('POST', \"array2excel.php\");\n    request.responseType = \"blob\";\n    request.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded\");\n    request.send(\"array2excel=\" + encodeURIComponent(json));\n}\n\u003c/script\u003e\n\u003cbody\u003e\n\u003cinput type=\"button\" onclick=\"array2excel()\" value=\"array2excel\" /\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Debug\n```php\nini_set('error_reporting', E_ALL );\nini_set('display_errors', 1 );\n\n$data = [\n    ['Debug', 123]\n];\n\nShuchkin\\SimpleXLSXGen::fromArray( $data )-\u003esaveAs('debug.xlsx');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuchkin%2Fsimplexlsxgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshuchkin%2Fsimplexlsxgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuchkin%2Fsimplexlsxgen/lists"}