2010-10-08 5 views
3

En utilisant ce code, je suis capable de créer un commentaire dans un fichier Excel.Impossible de trouver le commentaire phpexcel dans le fichier xlsx

$comment = $data_sheet->getCommentByColumnAndRow($col, 1); 
$comment->setAuthor($table_name . '.' . $field_name); 
$comment->setWidth('200px'); 
$comment->setHeight('24px'); 
$comment->setVisible(false); # ActiveCell.Comment.Visible = True 

$objCommentRichText = $comment->getText()->createTextRun($table_name . '.' . $field_name); 

lors de l'enregistrement du fichier a les commentaires qu'il contient, et peuvent être modifiés mais sur la réouverture de ce fichier l'objet de commentaires est dans un état par défaut.

$comment = $data_sheet->getComment('A1'); 

Le résultat est: -

$comment = PHPExcel_Comment Object (
    [_author:private] => Author 
    [_text:private] => PHPExcel_RichText Object ([_richTextElements:private] => Array ()) 
    [_width:private] => 96pt 
    [_marginLeft:private] => 59.25pt 
    [_marginTop:private] => 1.5pt 
    [_visible:private] => 
    [_height:private] => 55.5pt 
    [_fillColor:private] => PHPExcel_Style_Color Object (
     [_argb:private] => FFFFFFE1 
     [_isSupervisor:private] => 
     [_parent:private] => 
     [_parentPropertyName:private] => 
    ) 
) 

++ EDIT:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> 
    <authors><author>products.products_id</author><author>products.part_code</author><author>products.products_name</author><author>products.products_quantity</author><author>products.products_status</author><author>products.cost</author><author>products.cost_modifier</author><author>products.delivery_cost</author><author>products.shipping_strategy</author><author>products.products_weight</author><author>products.shipping_amount</author><author>products.products_price</author><author>products.rrp</author><author>products.trade</author><author>products_feed.amazon_price</author><author>products_feed.ebay_price</author></authors> 
    <commentList> 
    <comment ref="A1" authorId="0"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.products_id</t></r></text></comment> 
    <comment ref="B1" authorId="1"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.part_code</t></r></text></comment> 
    <comment ref="C1" authorId="2"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.products_name</t></r></text></comment> 
    <comment ref="D1" authorId="3"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.products_quantity</t></r></text></comment> 
    <comment ref="E1" authorId="4"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.products_status</t></r></text></comment> 
    <comment ref="F1" authorId="5"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.cost</t></r></text></comment> 
    <comment ref="G1" authorId="6"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.cost_modifier</t></r></text></comment> 
    <comment ref="H1" authorId="7"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.delivery_cost</t></r></text></comment> 
    <comment ref="I1" authorId="8"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.shipping_strategy</t></r></text></comment> 
    <comment ref="J1" authorId="9"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.products_weight</t></r></text></comment> 
    <comment ref="K1" authorId="10"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.shipping_amount</t></r></text></comment> 
    <comment ref="L1" authorId="11"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.products_price</t></r></text></comment> 
    <comment ref="M1" authorId="12"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.rrp</t></r></text></comment> 
    <comment ref="N1" authorId="13"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products.trade</t></r></text></comment> 
    <comment ref="O1" authorId="14"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products_feed.amazon_price</t></r></text></comment> 
    <comment ref="P1" authorId="15"><text><r><rPr><sz val="11"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>products_feed.ebay_price</t></r></text></comment> 
    </commentList> 
</comments> 

le commentaire existe donc dans le fichier .xlsx.

Aucun n'a ramassé les commentaires, pour le moment.

$comment = $data_sheet->getCommentByColumnAndRow($col, 1); 
$comment = $data_sheet->getComment('A'. $row); 
$comments = $data_sheet->getComments(); 

--edit Question, sont correctement chargés commentaires au format 'excel2007'?

Répondre

2

Le code est définitivement présent dans le lecteur Excel2007 pour charger les commentaires. Je devrais faire quelques tests pour confirmer si ça marche ou pas.

EDIT

enfin trouvé un peu de temps pour tester. En utilisant la version 1.7.5 et aussi le dernier code SVN, le lecteur Excel2007 lit avec succès tous les commentaires pour une feuille de calcul (vérifiée en utilisant la méthode getComments() pour la feuille de calcul), et getCommentByColumnAndRow() et getComment() méthodes retourne l'objet de commentaire pour la cellule demandée, en créant un nouveau commentaire s'il n'y en a pas déjà un.

Ceci est un comportement attendu.

La seule chose que je peux penser est que vous n'avez pas la feuille de calcul correcte data_sheet de $

3

Voici un extrait de code que j'utilisé pour extraire les commentaires des cellules en utilisant PHPExcel

$objPHPExcel = PHPExcel_IOFactory::load("MyExcelFile.xlsx"); 
    $objWorksheet = $objPHPExcel->getActiveSheet(); 

    // loop through each row in excel file 
    foreach ($objWorksheet->getRowIterator() as $row) { 

    $cellIterator = $row->getCellIterator(); 
    $cellIterator->setIterateOnlyExistingCells(true); 

    // loop through each column in row 
    foreach ($cellIterator as $cell) { 

     // get the value of the cell 
     $value = $cell->getValue(); 

     // get the comment in the cell (if a comment exists) 
     $comment = $objWorksheet->getComment($cell->getCoordinate())->getText(); 

    } 


    } 

ici est un lien vers le PHPExcel Comments Documentation

Questions connexes