woland99 has asked for the wisdom of the Perl Monks concerning the following question:

I just migrated to MS Office 2013 and I have problem with adding comments to Excel spreadsheet via Perl script.

My old code looked a bit like:

my $comment; $comment = $wsheet->Cells($row_num,$col_num)->{Comment}; if(defined $comment) { $wsheet->Cells($row_num,$col_num)->{Comment}->Text({Text => $cell_ +value}); } else { $wsheet->Cells($row_num,$col_num)->AddComment($cell_value); $comment = $wsheet->Cells($row_num,$col_num)->{Comment}; if(!defined $comment) { print STDERR "Could not add comment in row $row_num and column + $col_num\n"; } }
and it worked fine in Office 2003 but on Office 2013 I get:
Win32::OLE(0.1709) error 0x80010105: "The server threw an exception" in METHOD/PROPERTYGET "AddComment" at olelib.pl line 2834. Could not add comment in row 13 and column 6
Line 2834 is where AddComment is being called. This is confusing since I recorded the macro when adding comment and I get VB code virtually identical to the code on which I based that Office 2003 implementation. TIA for any pointers/info.

Replies are listed 'Best First'.
Re: Win32::OLE AddComment method and MS Office 2013
by poj (Abbot) on Nov 10, 2014 at 13:30 UTC

    Your code works for me with Office 2010 Excel 14, perl 5.16.1, Win32::OLE 0.1709.

    poj
Re: Win32::OLE AddComment method and MS Office 2013
by Anonymous Monk on Nov 10, 2014 at 09:00 UTC

    TIA for any pointers/info.

    Did ->Cells() succeed? What is the Count?

    Did you compare the 2003 and 2013 docs side by side (or both Cells and AddComment)?

      Yes.
      $wsheet->Cells($row_num,$col_num)
      is a defined Win32::OLE object. You can examine it in debugger and property 'Comment' is 'null' before and after call to AddComment. Docs for that call in 2003 and 2013 are the same. For now I used WriteExcel module as a quick workaround.

        s a defined Win32::OLE object.

        Yeah, it should always be a defined Win32::OLE object, because Cells() is documented to always return a Range ... even if the range is EMPTY