Laravel-datatables: Export Excel #Question

Created on 22 Dec 2016  路  4Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request

When exporting currency items or items with the type format:

    'type' => 'num-fmt',

Is there anyway for it to reflect this in excel to avoid the problems where excel warns about the column values being strings but looking like numbers.

So basically to define a column as being a number or currency column using export to excel.

I looked at exportOptions but I was not sure if this would solve the issue can anyone confirm if I am on the right track?

question

Most helpful comment

You can override the function below to generate your custom excel handler.

/**
     * Build excel file and prepare for export.
     *
     * @return \Maatwebsite\Excel\Writers\LaravelExcelWriter
     */
    protected function buildExcelFile()
    {
        /** @var \Maatwebsite\Excel\Excel $excel */
        $excel = app('excel');

        return $excel->create($this->getFilename(), function (LaravelExcelWriter $excel) {
            $excel->sheet('exported-data', function (LaravelExcelWorksheet $sheet) {
                $sheet->fromArray($this->getDataForExport());
            });
        });
    }

All 4 comments

I think this question can be answered better on the main excel repo. Thanks!

Agreed but because I am using the button for excel at the top of the datatable I don't know what code this is actually calling to handle the export or I might be able to figure this out myself, can you tell me what code is being called by the buttons and if this is override-able?

You can override the function below to generate your custom excel handler.

/**
     * Build excel file and prepare for export.
     *
     * @return \Maatwebsite\Excel\Writers\LaravelExcelWriter
     */
    protected function buildExcelFile()
    {
        /** @var \Maatwebsite\Excel\Excel $excel */
        $excel = app('excel');

        return $excel->create($this->getFilename(), function (LaravelExcelWriter $excel) {
            $excel->sheet('exported-data', function (LaravelExcelWorksheet $sheet) {
                $sheet->fromArray($this->getDataForExport());
            });
        });
    }

Thank you so much this should allow me to fix my issue :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vipin733 picture vipin733  路  3Comments

shadoWalker89 picture shadoWalker89  路  3Comments

jackrsantana picture jackrsantana  路  3Comments

ahmadbadpey picture ahmadbadpey  路  3Comments

sangnguyenplus picture sangnguyenplus  路  3Comments