Reading the source: even though there is "a font format for cell comments" defined, with hard-coded attributes, it's probably never used. Comments' text font, size and color appear to be even more deeply hard-coded. So, ugly solution would be to hack source, or re-define a sub in Excel::Writer::XLSX::Package::Comments package.
As to color index "81", I'm not sure but it looks like 64 and above is "default" i.e. black. Why 81 then? Don't know. To use different color for different comments, other than post-process XLSX files (which are ZIP archives, as you of course know), I have no other solutions.
| [reply] [d/l] |
#!perl
use strict;
use Win32::OLE 'in';
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # Die on Errors.
# config
my $dir = 'c:/temp/';
my $file = 'perl.xlsx';
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
$Excel->{DisplayAlerts} = 0;
#$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Open($dir.$file);
my $ws = $Book->Worksheets(1);
for my $c (in $ws->comments) {
print $c->text."\n";
my $str = $c->{'Shape'}->{'TextFrame'}->Characters();
$str->{'Font'}->{'ColorIndex'} = 3; # red
}
# close
$Book->Save;
$Excel->Quit();
undef $Book;
undef $Excel;
poj
| [reply] [d/l] |
Hello actionphotos,
Yes it can be done, see sample of code bellow:
Sorry I just noticed that you mentioned the text color and not the background color.
#!/usr/bin/perl
use strict;
use warnings;
use Excel::Writer::XLSX;
# Create a new Excel workbook
my $workbook = Excel::Writer::XLSX->new( 'perl.xlsx' );
# Add a worksheet
my $worksheet = $workbook->add_worksheet();
# Write a formatted and unformatted string, row and column notation.
$worksheet->write( 'C3', 'Hi Excel!');
$worksheet->write_comment( 'C3', 'Comment with Color', color => 'green
+' );
You can read more about the other options here Excel::Writer::XLSX/write_comment( $row, $column, $string, ... ).
Update: Reading again and again the documentation I do not think so it is possible to update the character color of the comment. You can update the character colors of the spreadsheet yes, but not the comments. In case you find a solution to your problem can you also share it here so someone else in the future might benefit from it.
Hope this helps, BR.
Seeking for Perl wisdom...on the process of learning...not there...yet!
| [reply] [d/l] [select] |