Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_array_formula applies format not correctly #18

Closed
AlexBroitman opened this issue Sep 5, 2012 · 3 comments
Closed

write_array_formula applies format not correctly #18

AlexBroitman opened this issue Sep 5, 2012 · 3 comments
Assignees
Labels

Comments

@AlexBroitman
Copy link

When I try to apply format to the cell range with write_array_formula() method, the format is applied only to first cell, not to the entire range.
Example:
$worksheet->write_array_formula('A1:C3', '{=2+2}', $workbook->add_format(border=>6, bold=>1));

@ghost ghost assigned jmcnamara Sep 5, 2012
@jmcnamara
Copy link
Owner

The current Excel::Writer::XLSX behaviour models Excel's behaviour which only adds formatting to the first cell.

However, Excel also adds formatted blank cells to the rest of the range. So perhaps Excel::Writer::XLSX should do the same.

I'll mark it as a bug/feature request and put it in the 0.51 milestone.

In the meantime you can work around this issue by adding formatting to the other cells in the range using write_blank() and a format. Something like this:

#!/usr/bin/perl 

use strict; 
use warnings; 
use Excel::Writer::XLSX; 

my $workbook  = Excel::Writer::XLSX->new( 'array_formula.xlsx' ); 
my $worksheet = $workbook->add_worksheet(); 
my $format    = $workbook->add_format( bold => 1 ); 

$worksheet->write( 'B1', [ [ 500, 10 ], [ 300, 15 ] ] ); 

$worksheet->write_array_formula( 'A1:A2', '{=SUM(B1:C1*B2:C2)}', $format ); 
$worksheet->write_blank( 'A2', $format ); 

__END__ 

@AlexBroitman
Copy link
Author

Thank you for the very quick answer.
Let me ask here one question.

How can I set a border to the range? I mean not to every cell in the range, but to the entire range.
For example in the code below I suppose to see double border around the entire range but not on every cell in the range:

$format = $workbook->add_format(border => 6);
$worksheet->apply_format('A1:C3', $format);

Thanks

@jmcnamara
Copy link
Owner

That isn't possible currently but it planned in the next +1 release, i.e., 0.51.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants