我正在尝试使用PHPSpreadsheet在XLSX工作表中创建注释。一切正常,除了默认情况下似乎没有办法隐藏注释-在LibreOffice中打开生成的Excel文件时,所有注释都会显示。 Comment
类确实具有setVisible
方法,但似乎被忽略了。
我正在通过Composer使用PHPSpreadsheet 1.9.0。
完整示例:
require ('vendor/autoload.php');
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
$excel = new Spreadsheet();
$ws = $excel->getActiveSheet();
$ws->setCellValue('A1', 'Hello');
$ws->getComment('A1')->getText()->createTextRun("This is a comment");
$ws->getComment('A1')->setVisible(false);
$writer = IOFactory::createWriter($excel, 'Xlsx');
$writer->save('test-comments.xlsx');
理论上,A1中的注释应该开始隐藏,但是默认显示。
编辑-一些其他信息。注释确实开始隐藏在Excel中,因此这可能表明LibreOffice出现了一些问题。但是,如果您在LibreOffice中隐藏注释,然后保存回XLSX并重新打开,则注释确实开始隐藏-因此,显然,这是PHPSpreadsheet编写注释的方式与LibreOffice期望的样子之间的某种不兼容。我已经针对Libreoffice Calc(#128447)提交了一个错误。
[如果有人偶然发现,这已被确认是LibreOffice中的错误。有关详细信息,请参见链接的错误报告。