in reply to Re: Spreadsheet::ParseXLSX question on merged cells
in thread Spreadsheet::ParseXLSX question on merged cells

Thanks, I tried it. Could not really find examples of it being used.

use Spreadsheet::ParseXLSX; use Spreadsheet::ParseXLSX::Cell; my $parser = Spreadsheet::ParseXLSX->new( ); my $workbook = $parser->parse($infile); print "workbook=$workbook\n"; my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $worksheet ( $workbook->worksheets() ) { my $cell = $worksheet->{Cells}[$row_min][$col_min] ; print Dumper($cell); my $toprint= $cell->is_merged() ? 'got merged' : 'unmerged'; print "$toprint\n"; }

prints $VAR1 = undef;

Can't call method "is_merged" on an undefined value at

So unless I am doing something wrong, there is no Merged or is_Merged property

Replies are listed 'Best First'.
Re^3: Spreadsheet::ParseXLSX question on merged cells
by ysth (Canon) on Nov 13, 2025 at 21:22 UTC
    Not all cells are going to be populated, and ones that don't will be undef, as you are seeing, not a cell object. Try it on a specific cell that you know has content. Or better yet, one you know is merged and one you know has content but is not merged.

      That is the problem. I want to say "if the cell in the col_min has no content (!$val) and is merged, then do A, else do B

      If I try:

      my $ans=$cell->is_merged()

      I get Can't call method "is_merged" on an undefined value

        You can test for definedness.
        #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Excel::Writer::XLSX; use Spreadsheet::ParseXLSX; { my $workbook = 'Excel::Writer::XLSX'->new('m.xlsx'); my $worksheet = $workbook->add_worksheet; my $f = $workbook->add_format; $worksheet->merge_range(2, 2, 3, 3, undef, $f); $worksheet->merge_range(4, 4, 5, 5, 'merged', $f); $workbook->close(); } { my $parser = 'Spreadsheet::ParseXLSX'->new; my $workbook = $parser->parse('m.xlsx'); my $worksheet = ($workbook->worksheets)[0]; for my $x (1 .. 5) { for my $y (1 .. 5) { my $cell = $worksheet->{Cells}[$x][$y]; print "[$x,$y] ", defined $cell ? $cell->is_merged : '-'; } print "\n"; } } __END__ [1,1] -[1,2] -[1,3] -[1,4] -[1,5] - [2,1] -[2,2] 1[2,3] 1[2,4] -[2,5] - [3,1] -[3,2] 1[3,3] 1[3,4] -[3,5] - [4,1] -[4,2] -[4,3] -[4,4] 1[4,5] 1 [5,1] -[5,2] -[5,3] -[5,4] 1[5,5] 1
        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]