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

0 showing up as blank cell #135

Closed
ejunker opened this issue May 29, 2014 · 7 comments
Closed

0 showing up as blank cell #135

ejunker opened this issue May 29, 2014 · 7 comments

Comments

@ejunker
Copy link

ejunker commented May 29, 2014

I apologize if this question has been asked before. I skimmed the closed issues and did not find anything.

When the following example code is ran it has 2 rows but the 0 shows up as a blank cell.

\Excel::create('test', function ($excel) {
    $excel->sheet('sheet', function ($sheet) {
        $sheet->fromArray(array(array('foo' => 0), array('foo' => 4)));
    });
})->export('xls');

I found this post on the PHPExcel site that shows how to get 0's to show up:
https://phpexcel.codeplex.com/discussions/346577

Here is what I had to change my code to so that 0's do not show up as blanks.

\Excel::create('test', function ($excel) {
    $excel->sheet('sheet', function ($sheet) {
        $sheet->fromArray(array(array('foo' => 0), array('foo' => 4)), null, 'A1', true);
    });
})->export('xls');

It also appears that if you pass 0 as a string "0" that it will work too.

I'm surprised that the default behavior is to show 0's as blank cells. Is there an easier way to get 0's to show up? Is there a global config option that I can set in one place so that I don't have to pass all those additional arguments every single time?

@MaatwebsiteSupport
Copy link
Contributor

Will be added with v1.1.0

@webr
Copy link

webr commented Jun 16, 2014

Hi, I'm having the same problem with imports. Any columns in my CSV that are '0' are returned as null.

@MaatwebsiteSupport
Copy link
Contributor

Could you make a new issue about this, because it's about importing and not exporting.

@webr
Copy link

webr commented Jun 16, 2014

Thanks, done here: #153

@philliskiragu
Copy link

philliskiragu commented Dec 17, 2016

I know this issue is closed but I am having the same problem with v2.1 When I export to csv the fields with 0 or null are blank cells.

 Excel::create('issues', function ($excel) use ($issues) {

                $excel->sheet('Sheet 1', function ($sheet) use ($issues) {

                    $sheet->fromArray($issues);
                });
            })->export('csv');

@alexpgates
Copy link

@philliskiragu I had this same issue, but found this note in the export documentation:

By default 0 is shown as an empty cell. If you want to change this behaviour, you can pass true as 4th parameter:

// Will show 0 as 0
$sheet->fromArray($data, null, 'A1', true);

http://www.maatwebsite.nl/laravel-excel/docs/export

Hopefully this will clear up some confusion if anyone else stumbles across this.

@ksidibe
Copy link

ksidibe commented Dec 9, 2019

@philliskiragu I had this same issue, but found this note in the export documentation:

By default 0 is shown as an empty cell. If you want to change this behaviour, you can pass true as 4th parameter:

// Will show 0 as 0
$sheet->fromArray($data, null, 'A1', true);

http://www.maatwebsite.nl/laravel-excel/docs/export

Hopefully this will clear up some confusion if anyone else stumbles across this.

That link is outdated. For those still looking for zeroes to appear as zeroes, here's the updated link to the part of the document that tells you how
https://docs.laravel-excel.com/3.1/exports/collection.html#strict-null-comparisons
Basically you simply do: use Maatwebsite\Excel\Concerns\WithStrictNullComparison;

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

6 participants