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

How to apply different columns #297

Open
bkmorse opened this issue Nov 2, 2022 · 1 comment
Open

How to apply different columns #297

bkmorse opened this issue Nov 2, 2022 · 1 comment

Comments

@bkmorse
Copy link

bkmorse commented Nov 2, 2022

I am trying to export to an xls file, there is multiple tabs in this export, but it uses the same set of columns, even though each sheet within the export does not contain the same columns

below is an example SheetCollection, is there a way using the FastExcel ->export to set what columns each array within that SheetCollection?

$sheets = new SheetCollection([
    'colors' => [
        'favorite' => 'green',
        'favorite' => 'blue',
        'favorite' => 'orange',
    ],
    'food' => [
        'type'  => 'italian',
        'type'  => 'french',
    ],
    'dogs' => [
        'name' => 'ruffus',
        'name' => 'marley'
    ]
]);

Trying to find a way so all 3 tabs in the spreadsheet use the appropriate columns per tab.

Expected outcome:

3 tabs
colors tab would have one column: favorite
food tab would have one column: type
dogs tab would have one column: name

@afiqiqmal
Copy link

Im also trouble to styling it. If we look at the codes, there is no way we can customize each of rows/cells style individually. Even method configureWriterUsing are only works for Options

What we can do, we need to overwrite writeRowsFromCollection in Exportable traits

from this

$all_rows = $collection->map(function ($value) {
           return WriterEntityFactory::createRowFromArray($value);
        })->toArray();

to

$all_rows = $collection->map(function ($value) {
            if ($value instanceof Row) {
                return $value;
            }
            
            return WriterEntityFactory::createRowFromArray($value);
        })->toArray();

so that, we can use like this

SheetCollection::make([
            new Row(
                [
                    new Cell(
                        'Year',
                        (new Style())->setCellAlignment('center')
                    )
                ],
                null
            ),
            [
                'Jan',
                'Feb',
                'March',
                'April',
            ],
            [
                100,
                299,
                493,
                4944,
            ],
        ])

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

No branches or pull requests

2 participants