PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

zeros (0) gets removed

Open Tejas20002 opened this issue 3 years ago • 4 comments

I have try this method to don't remove the zero (0)

 public function columnFormats(): array {
        return [
            'A' => NumberFormat::FORMAT_NUMBER,
            'B' => NumberFormat::FORMAT_TEXT,
            'C' => NumberFormat::FORMAT_NUMBER,
        ];
    }

I have also try this:

 public function columnFormats(): array {
        return [
            'A' => NumberFormat::FORMAT_NUMBER,
            'B' => '0',
            'C' => NumberFormat::FORMAT_NUMBER,
        ];
    }

I have also try this:

 public function columnFormats(): array {
        return [
            'A' => NumberFormat::FORMAT_NUMBER,
            'B' => '@',
            'C' => NumberFormat::FORMAT_NUMBER,
        ];
    }

I have also try this:

 public function columnFormats(): array {
        return [
            'A' => NumberFormat::FORMAT_NUMBER,
            'B' => NumberFormats::FORMAT_GENERAL,
            'C' => NumberFormat::FORMAT_NUMBER,
        ];
    }

I have also try to convert int to string in the view of my Laravel then also zero(0) get removed, I have use function to convert int to string:

  1. typecast
<table border="1">
    <thead>
    <tr>
        <th>#</th>
        <th>Single Open</th>
        <th>Amount</th>
    </tr>
    </thead>
    <tbody>
    {{ $i = 1 }}
    @foreach($opensingle as $jod)
        <tr>
            <td>{{ $i ?? '' ?? '1' }}</td>
            <td>{{ (string)$jod['open_digit'] }}</td>
            <td>{{ $jod['total_amount'] }}</td>
            {{ $i++ }}
        </tr>
    @endforeach
    </tbody>
</table>
  1. String function strval() and settype():
<table border="1">
    <thead>
    <tr>
        <th>#</th>
        <th>Single Open</th>
        <th>Amount</th>
    </tr>
    </thead>
    <tbody>
    {{ $i = 1 }}
    @foreach($opensingle as $jod)
        <tr>
            <td>{{ $i ?? '' ?? '1' }}</td>
            <td>{{ strval($jod['open_digit']) }}</td> OR <td>{{ settype($jod['open_digit'], "string") }}</td> // answer of strval is empty and settype is 1
            <td>{{ $jod['total_amount'] }}</td>
            {{ $i++ }}
        </tr>
    @endforeach
    </tbody>
</table>

Tejas20002 avatar May 31 '22 06:05 Tejas20002

If you're using Laravel, then perhaps it would be better if you asked about this on Laravel help

MarkBaker avatar May 31 '22 07:05 MarkBaker

If you're using Laravel, then perhaps it would be better if you asked about this on Laravel help

ohk thank you

Tejas20002 avatar May 31 '22 07:05 Tejas20002

PR #2813 resolved an issue that seems similar to this one. If you can test against master, please see if that resolves your issue.

oleibman avatar May 31 '22 14:05 oleibman

PR #2813 resolved an issue that seems similar to this one. If you can test against master, please see if that resolves your issue.

okay I will check out! but this issue is our side or SpartnerNL/Laravel-Excel

Tejas20002 avatar Jun 02 '22 11:06 Tejas20002

No update in over 4 months. Closing.

oleibman avatar Oct 24 '22 20:10 oleibman