tags:

views:

32

answers:

1

Hi

Using this code I am able to create a comment in an excel file.

 $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);

when saved the file has the comments in it, and can be edited however on re-opening this file the comment object is in default condition.

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

Result is :-

$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"&gt;
  <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>

So the comment exists in the .xlsx file.

None of these has picked up the comments, yet.

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

--EDIT Question, are comments correctly loaded in 'Excel2007' format ?

A: 

The code is definitely present within the Excel2007 Reader to load comments. I'd have to run some tests to confirm whether it's working or not.

Mark Baker