Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map attributes for import and export #6

Closed
rap2hpoutre opened this issue Apr 6, 2018 · 2 comments
Closed

Map attributes for import and export #6

rap2hpoutre opened this issue Apr 6, 2018 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rap2hpoutre
Copy link
Owner

rap2hpoutre commented Apr 6, 2018

ON HOLD. See: #13

Currently, when exporting a model, the columns names are exactly the same as those present in database (minus the ones that are hidden, like password for User model). So exporting a User model returns:

id name email
1 raph raph@example.com

I think we should add something that allows to choose the name of columns.

So calling this:

(new FastExcel(User::all))->mapAttributes([
    'column 1' => 'name',
    'Email' => 'email',
])->export('file.xlsx');

...should create this:

column 1 Email
raph raph@example.com

When #5 will be done, it should also work for import the same way. So it should be possible to do this to create a bunch of user instances:

$users = (new FastExcel(User::all))->mapAttributes([
    'column 1' => 'name',
    'Email' => 'email',
])->import('file.xlsx');
@rap2hpoutre rap2hpoutre added enhancement New feature or request help wanted Extra attention is needed labels Apr 6, 2018
@rap2hpoutre rap2hpoutre changed the title Map attributes export for import and export Map attributes for import and export Apr 6, 2018
@rap2hpoutre
Copy link
Owner Author

Done for import, via callback:

$users = (new FastExcel)->import('file.xlsx', function ($line) {
    return User::create([
        'name' => $line['Name'],
        'email' => $line['Email']
    ]);
});

Now we have to allow callback on export.

@rap2hpoutre
Copy link
Owner Author

Done on export too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant