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

custom column names before export #1565

Closed
3 tasks done
robertnicjoo opened this issue Mar 16, 2018 · 9 comments
Closed
3 tasks done

custom column names before export #1565

robertnicjoo opened this issue Mar 16, 2018 · 9 comments
Assignees
Labels

Comments

@robertnicjoo
Copy link

robertnicjoo commented Mar 16, 2018

Prerequisites

  • Able to reproduce the behavior outside of your code, the problem is isolated to Laravel Excel.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.1.12
  • Laravel version: 5.5.39
  • Package version: 2.1.0

Description

Hi,
I would like to know is it possible for me to edit columns before exporting my CSV file or not?
For example I have products table where has title description created_at updated_at what I want is to export something like title body as you see here i removed created_at , updated_at and also renamed my description column to body is that possible?

Steps to Reproduce

Expected behavior:
(What I want)

subject body
product one product one description
product two product two description

Actual behavior:
(What I have)

title description created_at updated_at
product one product one description 03-25-2018 03-25-2018
product two product two description 03-27-2018 03-28-2018

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Codes

currently I'm using default export code from samples, including no additional query etc. try to figure how should I change my code in order to export my data as I wish.

public function export() {
      $products = Product::all();
        Excel::create('products', function($excel) use($products) {
               $excel->sheet('sheet 1', function($sheet) use($products){
                $sheet->fromArray($products);
               });
        })->export('xls');

PS: what I try to create is exactly what this extension does in Magento,

sss

As you can see in this extension we are able to change default database column names, add/remove columns etc. (but i only need this two options), before export the data.

@JeroenVossen
Copy link
Contributor

JeroenVossen commented Mar 16, 2018

Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md) and add the missing information.

To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/contributing) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.

@robertnicjoo
Copy link
Author

thanks for responding, it is not actually an issue, is just a question.

i just want to know is such thing possible with help of this package or not?

just simple yes or no would be enough base on knowledge of the people who created this or have working experience with this package.

that's all I'm asking.

thanks.

@patrickbrouwers
Copy link
Member

@robertnicjoo we still need you to fill in the relevant parts of the issue template. It doesn't matter if it's a question or a bug. We now don't have enough information to help you. The difference between 2.1 and 3.0 e.g. is huge and the answer would totally differ based on that information.

Please fill in the issue template: https://github.com/Maatwebsite/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md

@robertnicjoo
Copy link
Author

@JeroenVossen @patrickbrouwers I have updated my question as you asked for, please help me solve my issue,

thank you.

@robertnicjoo
Copy link
Author

any comment on that?

@JeroenVossen
Copy link
Contributor

@robertnicjoo Thanks for adding the information. We will pick it up as soon as we have resources available (as stated in our support guidelines (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/support)).

@robertnicjoo
Copy link
Author

Ok, I get it to work with my custom names. There is tiny issue:

My data row will repeat twice in excel file.

Explain

I edited 5 columns of my database and I got 10

sdd

Codes

This is my updated code:

public function export(Request $request) {
      $products = Product::all();
      Excel::create('products', function($excel) use($products, $request) {
        $excel->sheet('sheet 1', function($sheet) use($products, $request){

          $ddd = $request->except('_token');
          foreach($ddd as $fff){
            $ddd[] = $fff;
          }

            $sheet->fromArray($products, null, 'A1', false, false);
            $sheet->row(1, $ddd);
        });
      })->export('csv');
      return redirect()->back();
}

any idea?

@robertnicjoo
Copy link
Author

Thanks for no support of your creation. My problem has solved.

@JeroenVossen
Copy link
Contributor

Thanks for no support of your creation.

What do you mean by this remark? I hope you realize this is open source software that is free for you to use, but holds no obligation for us on support. We will give support on the package itself on a best effort basis. If needed, we can also provide commercial support. Please read our support page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants