如何使用 phpspreadsheet html 阅读器不在单元格值中写入注释

时间:2021-07-23 16:28:13

标签: phpspreadsheet phpoffice-phpspreadsheet

我正在尝试向加载了 phpspreadsheet html 阅读器的 xlsx 文件添加注释。 这是由 PhpOffice\PhpSpreadsheet\Reader\Html 导入的 html。

<table>
    <thead>
    <tr>
        @foreach($headings as $heading)
            <th>{{$heading}}</th>
        @endforeach
    </tr>
    </thead>
    <tbody>
    @foreach($failures as $rowKey => $failure)
        <tr>
            @foreach($failure as $key => $value)
                @php
                $style = '';
                $comment = '';
                if (isset($failingAttributes[$rowKey])) {
                    if ($failingAttributes[$rowKey]->contains($key)) {
                        $style = 'background-color:#FC4140;';
                        $comment = $failuresMessages[$rowKey][$key];
                    }
                }
                @endphp
                <td style="{{$style}}">
                    @if($comment) <span style="visibility:hidden" class="comment">{{$comment}}</span> @endif
                    {{ $value }}
                </td>
            @endforeach
        </tr>
    @endforeach
    </tbody>
</table>

当注释正确添加到单元格时,它也会在单元格内写入值。 enter image description here 我想要的只是将 $value 写入单元格,同时保留注释: enter image description here

我尝试添加 style="visibility:hidden"style="display:none",但它忽略了它,结果与我的第一个屏幕截图相同。

是否可以在不将其添加到单元格值之前进行评论?

【相关功能链接】 https://github.com/PHPOffice/PhpSpreadsheet/blob/3c5750bddc959f3219aba78287bd88ef95a148ea/src/PhpSpreadsheet/Reader/Html.php#L345

0 个答案:

没有答案