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

Error generating tag numFmts in styles.xml when same num_format but different bg_color #283

Closed
andreagrassisogea opened this issue Mar 6, 2023 · 5 comments
Assignees

Comments

@andreagrassisogea
Copy link

andreagrassisogea commented Mar 6, 2023

I am using last version of Excel::Writer::XLSX and I have a problem when I add 2 different formats but with the same num_format.
The result is that in the file "styles.xml" (contained within the xlsx) the "count" of numFmts is correct but it is different from the list of numFmt inside the tag (because some item are repeated more times).
If I open this xlsx file using Microsoft Excel, all works fine and I don't notice the problem, but if I use this xlsx file in Microsoft Access to import in a new table, an error occurs.

Here an example to test the bug:

#!/usr/bin/perl -w
  
use strict;
use Excel::Writer::XLSX;

# Create a new Excel workbook
my $workbook  = Excel::Writer::XLSX->new("bug.xlsx");
my $worksheet = $workbook->add_worksheet("TEST");

my $f_body = $workbook->add_format(num_format => '@');
my $f_head = $workbook->add_format(num_format => '@', bg_color => 'yellow');

$worksheet->write_string(0, 0, "Col1", $f_head);
$worksheet->write_string(0, 1, "Col2", $f_head);
$worksheet->write_string(0, 2, "Col3", $f_head);

$worksheet->write_string(1, 0, "Row1", $f_body);
$worksheet->write_string(1, 1, "Row2", $f_body);
$worksheet->write_string(1, 2, "Row3", $f_body);

In "styles.xml" I find the following tags (numFmts has declared with 1 count but the items are 2 and they are duplicate):

<numFmts count="1">
<numFmt formatCode="@" numFmtId="164"/>
<numFmt formatCode="@" numFmtId="164"/>
</numFmts>
@jmcnamara
Copy link
Owner

Thanks for the detailed report. That looks like a bug. I'll look into it.

@jmcnamara jmcnamara self-assigned this Mar 6, 2023
jmcnamara added a commit that referenced this issue Mar 6, 2023
@jmcnamara
Copy link
Owner

I've pushed a fix for this to main. I'll see if it needs more test cases before I close it.

@andreagrassisogea
Copy link
Author

I have done some test and the old problem seems to have disappeared. Thanks for the quick solution !

@andreagrassisogea
Copy link
Author

andreagrassisogea commented Mar 7, 2023 via email

@jmcnamara
Copy link
Owner

Fixed in version Excel::Writer::XLSX version 1.11.

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

No branches or pull requests

2 participants