2017-01-30 66 views
0

是否可以在添加新的PHPExcel之前清除所有單元格註釋?我有工作代碼,增加了一個評論,但我想先明確在特定細胞中所有現有的評論:PHPExcel清除單元格註釋

$pexr = PHPExcel_IOFactory::createReader('Excel2007'); 
try { 
    $pex = $pexr->load($fn); 
    } catch (Exception $e) { 
    //... 
    return; 
    } 
} 
// ...   
sheet = $pex->getSheetByName($curMed); 
... 
$sheet->setCellValue($col . $row, $r[7]); 
$sheet->getStyle($col . $row)->getNumberFormat()->setFormatCode('#,##0'); 
$sheet->getComment($col . $row)->getText()->createText("My lovely comment\r\n"); 

不幸的是我找不到像文檔中的「清除」任何東西。

回答

2

評論被存儲爲數組,按工作表對象中的單元格地址進行索引;它提供了獲取和設置整個數組的方法;所以這是完全有可能檢索數組,爲要清除單元格未設置註釋,然後把數組回來覆蓋原:

$comments = $sheet->getComments(); 
if (isset($comments[$col . $row])) { 
    unset($comments[$col . $row]); 
    $sheet->setComments($comments); 
} 
+0

感謝,將溶液冷卻,將嘗試儘快確認! – MichaSchumann

+0

工程就像一個魅力,非常感謝你! – MichaSchumann