{"id":18153319,"url":"https://github.com/hugoseigle/symfony-import-export-bundle","last_synced_at":"2025-10-28T06:31:45.390Z","repository":{"id":260670518,"uuid":"880306153","full_name":"HugoSEIGLE/symfony-import-export-bundle","owner":"HugoSEIGLE","description":"Symfony Import-Export Bundle - 📄 Simplify data import and export in your Symfony applications with customizable templates, validation, and multilingual support.","archived":false,"fork":false,"pushed_at":"2025-02-11T13:51:23.000Z","size":5334,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T14:41:26.582Z","etag":null,"topics":["bundle","csv","export","import","symfony","xlsx"],"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/HugoSEIGLE.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-10-29T13:44:58.000Z","updated_at":"2025-02-11T13:51:04.000Z","dependencies_parsed_at":"2024-11-01T18:32:44.351Z","dependency_job_id":"507345ea-aa54-469d-b98e-ac36e4bf48b3","html_url":"https://github.com/HugoSEIGLE/symfony-import-export-bundle","commit_stats":null,"previous_names":["hugoseigle/symfony-import-export-bundle"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSEIGLE%2Fsymfony-import-export-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSEIGLE%2Fsymfony-import-export-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSEIGLE%2Fsymfony-import-export-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSEIGLE%2Fsymfony-import-export-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HugoSEIGLE","download_url":"https://codeload.github.com/HugoSEIGLE/symfony-import-export-bundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238606939,"owners_count":19500076,"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":["bundle","csv","export","import","symfony","xlsx"],"created_at":"2024-11-02T03:06:19.862Z","updated_at":"2025-10-28T06:31:40.037Z","avatar_url":"https://github.com/HugoSEIGLE.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Packagist Version](https://img.shields.io/packagist/v/hugoseigle/symfony-import-export-bundle)\n![Total Downloads](https://img.shields.io/packagist/dt/hugoseigle/symfony-import-export-bundle)\n\n# 📦 Symfony ImportExportBundle\n\nThe SymfonyImportExportBundle simplifies data import, export, and template generation in Symfony applications. By leveraging Doctrine entities and Symfony forms, this bundle provides a seamless data management workflow.\n\n## 🚀 Installation\n\n### Install the bundle via Composer:\n\n```bash\ncomposer require hugoseigle/symfony-import-export-bundle\n```\n\n### Register the bundle in config/bundles.php:\n\n```php\n\nSymfonyImportExportBundle\\SymfonyImportExportBundle::class =\u003e ['all' =\u003e true],\n```\n\n## ⚙️ Configuration\n\n### Set up import_export.yaml in config/packages:\n\n``` yaml\n\nimport_export:\n  date_format: 'Y-m-d'\n  bool_true: 'true'\n  bool_false: 'false'\n  importers:\n    App\\Entity\\Product:\n      fields:\n        - name\n        - description\n        - price\n        - active\n        - createdAt\n        - updatedAt\n      allow_delete: true\n      unique_fields: ['name']\n```\n\n### Configuration Options\n\n``` yaml\n    date_format: Format used for dates in import/export operations.\n    bool_true / bool_false: Values for boolean true and false to ensure compatibility with different data sources.\n    importers: Configure entity fields for import:\n        fields: Define the fields to import.\n        allow_delete: Enable or disable deletion of existing records.\n        unique_fields: Specify unique fields for identifying existing entities.\n```\n\n## 📄 Usage\n\n### ✨ Exporter\n\nThe Exporter allows exporting data from entities into CSV or XLSX files.\n#### Basic Export Usage\n\n```php\n\nuse SymfonyImportExportBundle\\Services\\Export\\ExporterInterface;\n\n// Inject the ExporterInterface\npublic function exportData(ExporterInterface $exporter): Response\n{\n    $query = $this-\u003eproductRepository-\u003eyourQueryMethod();\n\n    return $exporter-\u003eexportCsv($query, ['getName', 'getDescription', ...], 'fileName', ExporterInterface::XLSX); // or 'csv'\n}\n```\n\n### ✨ Importer\n\nThe Importer allows importing data from CSV or XLSX files into entities, with validation handled by Symfony Forms.\n\n#### Setting Up the Import Form\n\n    Note: For boolean fields, set empty_data to false or true explicitly in the form type to ensure values are not interpreted as null.\n\n```php\n\n// src/Form/ProductType.php\n\nuse Symfony\\Component\\Form\\AbstractType;\nuse Symfony\\Component\\Form\\FormBuilderInterface;\nuse Symfony\\Component\\OptionsResolver\\OptionsResolver;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\CheckboxType;\n\nclass ProductType extends AbstractType\n{\n    public function buildForm(FormBuilderInterface $builder, array $options): void\n    {\n        $builder\n            -\u003eadd('name')\n            -\u003eadd('description')\n            -\u003eadd('price')\n            -\u003eadd('active', CheckboxType::class, [\n                'required' =\u003e false,\n                'empty_data' =\u003e 'false', // Ensures boolean fields are handled correctly\n            ]);\n    }\n\n    public function configureOptions(OptionsResolver $resolver): void\n    {\n        $resolver-\u003esetDefaults([\n            'data_class' =\u003e Product::class,\n        ]);\n    }\n}\n```\n\n#### Importing Data\n\n```php\n\nuse SymfonyImportExportBundle\\Services\\Import\\ImporterInterface;\n\n// Inject the ImporterInterface\npublic function importData(Request $request, ImporterInterface $importer): Response\n{\n    $file = $request-\u003efiles-\u003eget('import_file'); // Retrieve file from the form or request\n    $importer-\u003eimport($file, Product::class, ProductType::class);\n\n    if ($importer-\u003eisValid()) {\n        $summary = $importer-\u003egetSummary();\n\n        foreach ($summary['created'] as $created) {\n            $this-\u003eentityManager-\u003epersist($created);\n        }\n\n        foreach ($summary['updated'] as $updated) {\n            $this-\u003eentityManager-\u003epersist($updated);\n        }\n\n        foreach ($summary['deleted'] as $deleted) {\n            $deleted-\u003edelete();\n        }\n\n        $this-\u003eentityManager-\u003eflush();\n\n        return new Response(\"Import successful! {$summary['inserted']} inserted, {$summary['updated']} updated.\");\n    } else {\n        $errors = $importer-\u003egetErrors();\n        return new Response(\"Import failed with errors: \" . implode(', ', $errors));\n    }\n}\n```\n\n### ✨ Import Template Generator\n\nThe Import Template Generator creates CSV or XLSX templates with headers based on configured fields, allowing users to download pre-formatted templates.\nGenerating an Import Template\n\n```php\n\nuse SymfonyImportExportBundle\\Services\\Import\\ImporterTemplateInterface;\n\n// Inject the ImporterTemplateInterface\npublic function generateImportTemplate(ImporterTemplateInterface $templateGenerator): Response\n{\n    return $templateGenerator-\u003egetImportTemplate(Product::class, ImporterInterface::XLSX); // or 'csv'\n}\n```\n\n## 🔧 Advanced Usage\n\n### Customizing Field Translations\n\nTo translate field names, add them to your translations/messages.yaml file:\n\n```yaml\n\nimport_export:\n  name: \"Product Name\"\n  description: \"Product Description\"\n  price: \"Price\"\n  active: \"Available\"\n```\n\n### Error Handling and Custom Translations\n\nEach validation error and import/export error can be translated. For example:\n\n```yaml\n\nimport_export:\n  missing_field: \"Missing field: {{ field }}\"\n  invalid_boolean: \"Invalid boolean value for: {{ field }}\"\n  invalid_datetime: \"Invalid date format for: {{ field }}\"\n  invalid_headers: \"The headers in the file do not match the expected format.\"\n```\n\n🛠 FAQ\n\nQ: How do I customize date formats for imports?\nA: Adjust the date_format option in import_export.yaml.\n\nQ: How are boolean values handled during import?\nA: Ensure the bool_true and bool_false values are configured in import_export.yaml to match data inputs. Set empty_data on boolean fields in the form.\n\nQ: Can I specify unique fields for updating records?\nA: Yes, add unique_fields in the configuration to identify existing records.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugoseigle%2Fsymfony-import-export-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugoseigle%2Fsymfony-import-export-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugoseigle%2Fsymfony-import-export-bundle/lists"}