【发布时间】:2014-12-16 23:39:25
【问题描述】:
使用 asimlqt/php-google-spreadsheet-client 标头必须在更新或插入行之前设置。当用户选择工作表时,我想检查标题是否是我想要的,或者它们是否丢失。我试图获取 cell(1,1) 的内容,如果它不等于我想要的内容,则创建所有标题。问题是,如果 cell(1,1) 为空,我会得到一个
“PHP 致命错误:在非对象上调用成员函数 getContent()”
如何在拨打电话时检查是否为空而不出错?
这是我的代码:
$cellFeed = $worksheet->getCellFeed();
$cell1 = $cellFeed->getCell(1,1)->getContent();
if ($cell1 !== 'datein'){
$cellFeed->editCell(1,1, 'datein');
$cellFeed->editCell(1,2, 'timein');
$cellFeed->editCell(1,3, 'dateout');
$cellFeed->editCell(1,4, 'timeout');
$cellFeed->editCell(1,5, 'note');
}
感谢@eddyparkinson 的解决方案
$cell1 = $cellFeed->getCell(1,1)
if (!is_object($cell1) || $cell1->getContent() !== 'datein'){
【问题讨论】:
标签: php google-spreadsheet-api