{"id":18256828,"url":"https://github.com/boundstate/yii2-importexport","last_synced_at":"2025-04-08T22:28:43.698Z","repository":{"id":32654894,"uuid":"36242256","full_name":"boundstate/yii2-importexport","owner":"boundstate","description":null,"archived":false,"fork":false,"pushed_at":"2016-08-12T19:35:20.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T17:43:18.762Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"box-builder/box","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boundstate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-25T16:37:40.000Z","updated_at":"2019-03-14T03:52:44.000Z","dependencies_parsed_at":"2022-08-21T09:20:29.618Z","dependency_job_id":null,"html_url":"https://github.com/boundstate/yii2-importexport","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boundstate%2Fyii2-importexport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boundstate%2Fyii2-importexport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boundstate%2Fyii2-importexport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boundstate%2Fyii2-importexport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boundstate","download_url":"https://codeload.github.com/boundstate/yii2-importexport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247938354,"owners_count":21021507,"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":[],"created_at":"2024-11-05T10:23:50.570Z","updated_at":"2025-04-08T22:28:43.681Z","avatar_url":"https://github.com/boundstate.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii2-importexport\n\n  Extension for the Yii2 framework for importing and exporting data with [PHPExcel].\n\n## Installation\n\n  The preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\n  Either run\n\n    php composer.phar require --prefer-dist boundstate/yii2-importexport \"*\"\n\n  or add\n\n    \"boundstate/yii2-importexport\": \"*\"\n\n  to the require section of your `composer.json` file.\n\n## Usage\n\n  Implement the `ImportInterface` and/or `ExportInterface`:\n\n    class Contact extends \\yii\\db\\ActiveRecord implements ImportInterface, ExportInterface\n    {\n        ...\n\n        public function import($reader, $row, $data)\n    \t{\n    \t    if ($row == 0) {\n    \t        if ($data != ['First Name', 'Last Name', 'Email']) {\n    \t            $reader-\u003eaddError($row, 'Invalid headers.');\n    \t            return false;\n    \t        }\n    \t        // Skip header row\n    \t        return true;\n    \t    }\n\n    \t    // Create contact from data\n    \t    $contact = new Contact;\n    \t    ...\n        }\n\n        public function export() {\n            return self::find()-\u003easArray()-\u003eall();\n        }\n    }\n\n  Now you can import data using `ExcelReader` and your class as the `destination`:\n\n    public function actionImport()\n    {\n        $form = new ImportForm();\n        $form-\u003efile = UploadedFile::getInstanceByName('file');\n\n        if ($form-\u003evalidate()) {\n            Contact::deleteAll();\n            $reader = new ExcelReader(['destination' =\u003e Contact::className()]);\n            $reader-\u003eimport($form-\u003efile-\u003etempName);\n            if ($reader-\u003egetErrors()) {\n                // Handle errors\n                ...\n            }\n        }\n        return $form;\n    }\n\n  Or export data using `ExcelWriter` and your class as the `source`:\n\n    public function actionExport()\n    {\n\t\t$writer = new ExcelWriter(['source' =\u003e Contact::className()]);\n        $filename = $writer-\u003ewrite('Excel2007');\n        Yii::$app-\u003eresponse-\u003esendFile($filename, 'contacts.xlsx')-\u003esend();\n    }\n\n[PHPExcel]: https://github.com/PHPOffice/PHPExcel","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboundstate%2Fyii2-importexport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboundstate%2Fyii2-importexport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboundstate%2Fyii2-importexport/lists"}