Skip to content

Commit 3374f57

Browse files
committed
Added tests fcr default hyperlink style.
1 parent d7ac1b2 commit 3374f57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+446
-80
lines changed

lib/Excel/Writer/XLSX/Format.pm

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ sub new {
4040
_xf_index => undef,
4141
_dxf_index => undef,
4242

43-
_num_format => 0,
44-
_num_format_index => 0,
45-
_font_index => 0,
46-
_has_font => 0,
47-
_has_dxf_font => 0,
48-
_font => 'Calibri',
49-
_size => 11,
50-
_bold => 0,
51-
_italic => 0,
52-
_color => 0x0,
53-
_underline => 0,
54-
_font_strikeout => 0,
55-
_font_outline => 0,
56-
_font_shadow => 0,
57-
_font_script => 0,
58-
_font_family => 2,
59-
_font_charset => 0,
60-
_font_scheme => 'minor',
61-
_font_condense => 0,
62-
_font_extend => 0,
63-
_theme => 0,
64-
_hyperlink => 0,
65-
_xf_id => 0,
43+
_num_format => 0,
44+
_num_format_index => 0,
45+
_font_index => 0,
46+
_has_font => 0,
47+
_has_dxf_font => 0,
48+
_font => 'Calibri',
49+
_size => 11,
50+
_bold => 0,
51+
_italic => 0,
52+
_color => 0x0,
53+
_underline => 0,
54+
_font_strikeout => 0,
55+
_font_outline => 0,
56+
_font_shadow => 0,
57+
_font_script => 0,
58+
_font_family => 2,
59+
_font_charset => 0,
60+
_font_scheme => 'minor',
61+
_font_condense => 0,
62+
_font_extend => 0,
63+
_theme => 0,
64+
_hyperlink => 0,
65+
_xf_id => 0,
6666

6767
_hidden => 0,
6868
_locked => 1,
@@ -680,17 +680,19 @@ sub set_rotation {
680680
#
681681
# set_hyperlink()
682682
#
683-
# Set the properties for the hyperlink style.
683+
# Set the properties for the hyperlink style. This isn't a public method. To
684+
# be fixed when styles are supported.
684685
#
685686
sub set_hyperlink {
686687

687-
my $self = shift;
688+
my $self = shift;
689+
my $hyperlink = shift;
688690

689-
$self->{_hyperlink} = 1;
690-
$self->{_xf_id} = 1;
691+
$self->{_xf_id} = 1;
691692

692693
$self->set_underline( 1 );
693694
$self->set_theme( 10 );
695+
$self->{_hyperlink} = $hyperlink;
694696
}
695697

696698

lib/Excel/Writer/XLSX/Package/Packager.pm

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,16 @@ sub _write_content_types_file {
544544
#
545545
sub _write_styles_file {
546546

547-
my $self = shift;
548-
my $dir = $self->{_package_dir};
549-
my $xf_formats = $self->{_workbook}->{_xf_formats};
550-
my $palette = $self->{_workbook}->{_palette};
551-
my $font_count = $self->{_workbook}->{_font_count};
552-
my $num_format_count = $self->{_workbook}->{_num_format_count};
553-
my $border_count = $self->{_workbook}->{_border_count};
554-
my $fill_count = $self->{_workbook}->{_fill_count};
555-
my $custom_colors = $self->{_workbook}->{_custom_colors};
556-
my $dxf_formats = $self->{_workbook}->{_dxf_formats};
547+
my $self = shift;
548+
my $dir = $self->{_package_dir};
549+
my $xf_formats = $self->{_workbook}->{_xf_formats};
550+
my $palette = $self->{_workbook}->{_palette};
551+
my $font_count = $self->{_workbook}->{_font_count};
552+
my $num_format_count = $self->{_workbook}->{_num_format_count};
553+
my $border_count = $self->{_workbook}->{_border_count};
554+
my $fill_count = $self->{_workbook}->{_fill_count};
555+
my $custom_colors = $self->{_workbook}->{_custom_colors};
556+
my $dxf_formats = $self->{_workbook}->{_dxf_formats};
557557

558558
my $rels = Excel::Writer::XLSX::Package::Styles->new();
559559

@@ -568,7 +568,6 @@ sub _write_styles_file {
568568
$fill_count,
569569
$custom_colors,
570570
$dxf_formats,
571-
572571
);
573572

574573
$rels->_set_xml_writer( $dir . '/xl/styles.xml' );

lib/Excel/Writer/XLSX/Package/Styles.pm

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ sub new {
4242
my $fh = shift;
4343
my $self = Excel::Writer::XLSX::Package::XMLwriter->new( $fh );
4444

45-
$self->{_xf_formats} = undef;
46-
$self->{_palette} = [];
47-
$self->{_font_count} = 0;
48-
$self->{_num_format_count} = 0;
49-
$self->{_border_count} = 0;
50-
$self->{_fill_count} = 0;
51-
$self->{_custom_colors} = [];
52-
$self->{_dxf_formats} = [];
53-
$self->{_has_hyperlink} = 0;
45+
$self->{_xf_formats} = undef;
46+
$self->{_palette} = [];
47+
$self->{_font_count} = 0;
48+
$self->{_num_format_count} = 0;
49+
$self->{_border_count} = 0;
50+
$self->{_fill_count} = 0;
51+
$self->{_custom_colors} = [];
52+
$self->{_dxf_formats} = [];
53+
$self->{_has_hyperlink} = 0;
54+
$self->{_hyperlink_font_id} = 0;
5455

5556
bless $self, $class;
5657

@@ -121,14 +122,14 @@ sub _set_style_properties {
121122

122123
my $self = shift;
123124

124-
$self->{_xf_formats} = shift;
125-
$self->{_palette} = shift;
126-
$self->{_font_count} = shift;
127-
$self->{_num_format_count} = shift;
128-
$self->{_border_count} = shift;
129-
$self->{_fill_count} = shift;
130-
$self->{_custom_colors} = shift;
131-
$self->{_dxf_formats} = shift;
125+
$self->{_xf_formats} = shift;
126+
$self->{_palette} = shift;
127+
$self->{_font_count} = shift;
128+
$self->{_num_format_count} = shift;
129+
$self->{_border_count} = shift;
130+
$self->{_fill_count} = shift;
131+
$self->{_custom_colors} = shift;
132+
$self->{_dxf_formats} = shift;
132133
}
133134

134135

@@ -391,6 +392,10 @@ sub _write_font {
391392

392393
if ( $format->{_hyperlink} ) {
393394
$self->{_has_hyperlink} = 1;
395+
396+
if ( !$self->{_hyperlink_font_id} ) {
397+
$self->{_hyperlink_font_id} = $format->{_font_index};
398+
}
394399
}
395400
}
396401

@@ -773,10 +778,10 @@ sub _write_cell_style_xfs {
773778
$self->xml_start_tag( 'cellStyleXfs', @attributes );
774779

775780
# Write the style_xf element.
776-
$self->_write_style_xf(0, 0);
781+
$self->_write_style_xf( 0, 0 );
777782

778783
if ( $self->{_has_hyperlink} ) {
779-
$self->_write_style_xf(1, 1);
784+
$self->_write_style_xf( 1, $self->{_hyperlink_font_id} );
780785
}
781786

782787
$self->xml_end_tag( 'cellStyleXfs' );
@@ -824,12 +829,12 @@ sub _write_cell_xfs {
824829
#
825830
sub _write_style_xf {
826831

827-
my $self = shift;
828-
my $is_hyperlink = shift;
829-
my $num_fmt_id = 0;
830-
my $font_id = shift;
831-
my $fill_id = 0;
832-
my $border_id = 0;
832+
my $self = shift;
833+
my $has_hyperlink = shift;
834+
my $font_id = shift;
835+
my $num_fmt_id = 0;
836+
my $fill_id = 0;
837+
my $border_id = 0;
833838

834839
my @attributes = (
835840
'numFmtId' => $num_fmt_id,
@@ -838,7 +843,7 @@ sub _write_style_xf {
838843
'borderId' => $border_id,
839844
);
840845

841-
if ( $is_hyperlink ) {
846+
if ( $has_hyperlink ) {
842847
push @attributes, ( 'applyNumberFormat' => 0 );
843848
push @attributes, ( 'applyFill' => 0 );
844849
push @attributes, ( 'applyBorder' => 0 );

lib/Excel/Writer/XLSX/Workbook.pm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ sub new {
142142
$self->add_format( xf_index => 0 );
143143
}
144144

145+
# Add a default URL format.
146+
$self->{_default_url_format} = $self->add_format( hyperlink => 1 );
147+
145148
# Check for a filename unless it is an existing filehandle
146149
if ( not ref $self->{_filename} and $self->{_filename} eq '' ) {
147150
carp 'Filename required by Excel::Writer::XLSX->new()';
@@ -369,7 +372,7 @@ sub add_worksheet {
369372
$self->{_optimization},
370373
$self->{_tempdir},
371374
$self->{_excel2003_style},
372-
375+
$self->{_default_url_format},
373376
);
374377

375378
my $worksheet = Excel::Writer::XLSX::Worksheet->new( @init_data );
@@ -1218,6 +1221,9 @@ sub _set_default_xf_indices {
12181221

12191222
my $self = shift;
12201223

1224+
# Delete the default url format.
1225+
splice @{ $self->{_formats} }, 1, 1;
1226+
12211227
for my $format ( @{ $self->{_formats} } ) {
12221228
$format->get_xf_index();
12231229
}

lib/Excel/Writer/XLSX/Worksheet.pm

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,19 @@ sub new {
5555
my $colmax = 16_384;
5656
my $strmax = 32767;
5757

58-
$self->{_name} = $_[0];
59-
$self->{_index} = $_[1];
60-
$self->{_activesheet} = $_[2];
61-
$self->{_firstsheet} = $_[3];
62-
$self->{_str_total} = $_[4];
63-
$self->{_str_unique} = $_[5];
64-
$self->{_str_table} = $_[6];
65-
$self->{_date_1904} = $_[7];
66-
$self->{_palette} = $_[8];
67-
$self->{_optimization} = $_[9] || 0;
68-
$self->{_tempdir} = $_[10];
69-
$self->{_excel2003_style} = $_[11];
58+
$self->{_name} = $_[0];
59+
$self->{_index} = $_[1];
60+
$self->{_activesheet} = $_[2];
61+
$self->{_firstsheet} = $_[3];
62+
$self->{_str_total} = $_[4];
63+
$self->{_str_unique} = $_[5];
64+
$self->{_str_table} = $_[6];
65+
$self->{_date_1904} = $_[7];
66+
$self->{_palette} = $_[8];
67+
$self->{_optimization} = $_[9] || 0;
68+
$self->{_tempdir} = $_[10];
69+
$self->{_excel2003_style} = $_[11];
70+
$self->{_default_url_format} = $_[12];
7071

7172
$self->{_ext_sheets} = [];
7273
$self->{_fileclosed} = 0;
@@ -2806,12 +2807,16 @@ sub write_url {
28062807
return -5;
28072808
}
28082809
2809-
28102810
# Write previous row if in in-line string optimization mode.
28112811
if ( $self->{_optimization} == 1 && $row > $self->{_previous_row} ) {
28122812
$self->_write_single_row( $row );
28132813
}
28142814
2815+
# Add the default URL format.
2816+
if ( !defined $xf ) {
2817+
$xf = $self->{_default_url_format};
2818+
}
2819+
28152820
# Write the hyperlink string.
28162821
$self->write_string( $row, $col, $str, $xf );
28172822

t/regression/chart_bar08.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ my $data = [
4646

4747
];
4848

49+
# Turn off default URL format for testing.
50+
$worksheet->{_default_url_format} = undef;
51+
4952
$worksheet->write( 'A1', $data );
5053
$worksheet->write( 'A7', 'http://www.perl.com/' );
5154

t/regression/chart_bar11.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ my $data = [
7373

7474
];
7575

76+
# Turn off default URL format for testing.
77+
$worksheet->{_default_url_format} = undef;
78+
7679
$worksheet->write( 'A1', $data );
7780
$worksheet->write( 'A7', 'http://www.perl.com/' );
7881
$worksheet->write( 'A8', 'http://www.perl.org/' );

t/regression/chart_bar14.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ my $data = [
5757

5858
];
5959

60+
# Turn off default URL format for testing.
61+
$worksheet2->{_default_url_format} = undef;
62+
6063
$worksheet2->write( 'A1', $data );
6164
$worksheet2->write( 'A6', 'http://www.perl.com/' );
6265

t/regression/escapes04.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ use Excel::Writer::XLSX;
3535
my $workbook = Excel::Writer::XLSX->new( $got_filename );
3636
my $worksheet = $workbook->add_worksheet();
3737

38+
39+
# Turn off default URL format for testing.
40+
$worksheet->{_default_url_format} = undef;
41+
3842
$worksheet->write_url( 'A1', 'http://www.perl.com/?a=1&b=2' );
3943

4044
$workbook->close();

t/regression/escapes05.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ my $workbook = Excel::Writer::XLSX->new( $got_filename );
3636
my $worksheet1 = $workbook->add_worksheet( "Start" );
3737
my $worksheet2 = $workbook->add_worksheet( "A & B" );
3838

39+
# Turn off default URL format for testing.
40+
$worksheet1->{_default_url_format} = undef;
41+
3942
$worksheet1->write_url( 'A1', q(internal:'A & B'!A1), 'Jump to A & B' );
4043

4144
$workbook->close();

t/regression/escapes07.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ use Excel::Writer::XLSX;
3535
my $workbook = Excel::Writer::XLSX->new( $got_filename );
3636
my $worksheet = $workbook->add_worksheet();
3737

38+
# Turn off default URL format for testing.
39+
$worksheet->{_default_url_format} = undef;
40+
3841
$worksheet->write_url( 'A1', q(http://example.com/!"$%&'( )*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~) );
3942

4043
$workbook->close();

t/regression/escapes08.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ use Excel::Writer::XLSX;
3535
my $workbook = Excel::Writer::XLSX->new( $got_filename );
3636
my $worksheet = $workbook->add_worksheet();
3737

38+
# Turn off default URL format for testing.
39+
$worksheet->{_default_url_format} = undef;
40+
3841
# Test an already escapted string.
3942
$worksheet->write_url( 'A1', 'http://example.com/%5b0%5d', 'http://example.com/[0]' );
4043

t/regression/hyperlink01.t

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ use Excel::Writer::XLSX;
3737
my $workbook = Excel::Writer::XLSX->new( $got_filename );
3838
my $worksheet = $workbook->add_worksheet();
3939

40-
$worksheet->write_url( 'A1', 'http://www.perl.org/' );
40+
# Turn off default URL format for testing.
41+
$worksheet->{_default_url_format} = undef;
42+
43+
$worksheet->write_url( 'A1', 'http://www.perl.org/');
4144

4245
$workbook->close();
4346

t/regression/hyperlink02.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ use Excel::Writer::XLSX;
3737
my $workbook = Excel::Writer::XLSX->new( $got_filename );
3838
my $worksheet = $workbook->add_worksheet();
3939

40+
# Turn off default URL format for testing.
41+
$worksheet->{_default_url_format} = undef;
42+
4043
$worksheet->write_url( 'A1', 'http://www.perl.org/' );
4144
$worksheet->write_url( 'D4', 'http://www.perl.org/' );
4245
$worksheet->write_url( 'A8', 'http://www.perl.org/' );

t/regression/hyperlink03.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ my $workbook = Excel::Writer::XLSX->new( $got_filename );
3838
my $worksheet1 = $workbook->add_worksheet();
3939
my $worksheet2 = $workbook->add_worksheet();
4040

41+
# Turn off default URL format for testing.
42+
$worksheet1->{_default_url_format} = undef;
43+
$worksheet2->{_default_url_format} = undef;
44+
4145
$worksheet1->write_url( 'A1', 'http://www.perl.org/' );
4246
$worksheet1->write_url( 'D4', 'http://www.perl.org/' );
4347
$worksheet1->write_url( 'A8', 'http://www.perl.org/' );

0 commit comments

Comments
 (0)