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

Does not return background color of a cell. #78

Open
bulrush15 opened this issue Sep 27, 2017 · 0 comments
Open

Does not return background color of a cell. #78

bulrush15 opened this issue Sep 27, 2017 · 0 comments

Comments

@bulrush15
Copy link

When using my code getcellcolor(), I get undef or garbage back that is meaningless. Here is my subroutine below.

###########################################################################
# In: Workbook object;
#     Sheet object;
#     row number (0-based);
#     col number (0-based);
#     XLSX filename (string);
#     tab name (string);
#     row in spreadsheet (just $row+1), 1-based.
# Out: String of cell contents.

# How the parameters passed in are created:
# my $wkbkin=$parser->parse($xlsfnin);
#     if (not $sheetin=$wkbkin->worksheet(0)) # Get first tab.
#         {
#         $s=$prefixsp."$procname ERROR: Could not get first tab in $xlsfnin";
#         print "$s\n";
#         $err=$s;
#         exit 1;
#         }
sub getcellcolor
{my($wkbkin,$sheetin,$row,$col,$xlsfnin,$tab,$zpos)=@_;
my($s,$t);

my $procname=(caller(0))[3];

my $prefixsp='  ';
my $new='';
my $cellin;
my $v='';

eval {
    $cellin=$sheetin->get_cell($row,$col);
    };
if ($@)
    {
    $s="$procname ERROR cell ".makecellname($row,$col).
    " from XLSX sheetin->get_cell. ";
    if ( defined($@) and (length($@)>0) )
        {
        $s.="\n\  $@ error: ".$@;
        }
    writeerr($s);
    return '';
    }

# Get value for debugging.
eval {
    $v=$cellin->value();
    };
if ($@)
    {
    $s="$procname ERROR cell ".makecellname($row,$col).
    ": from XLSX sheetin->value. ";
    writeerr($s);
    usleep $optsleep;
    }

my $bgcolor='';
if ($cellin)
    {
    my $format=$cellin->get_format();
    my $fillref=$format->{Fill};
    my @fillarr=@$fillref;
    my $idx='';
    if (defined($cellin->{Format}->{Fill}->[2]))
        {
        $idx=$cellin->{Format}->{Fill}->[2]; # Get background color index of this cell.
        if ($idx=~m/^[\d]+$/)
            {
            $bgcolor=$wkbkin->color_idx_to_rgb($idx);
            }
        else {
            $s="$procname ERROR cell ".makecellname($row,$col).": ".
            "Background color was blank for index '$idx'.";
            writeerr($s);
            sleep 1;
            }
        }
    #$font=$format->{Font}; # Returns font.
    #my $idx=$font->{Color}; # Returns color index.
    #my $rgbcolor=$ssin->ColorIdxToRGB(0,$idx); # Return RGB color as 6 ctr string.
    $s="$procname: ".makecellname($row,$col)." background ='$bgcolor'".
    ".  Val=$v";
    debugprgif($s,'  ');
    }
else {
   $s=$prefixsp."$procname ERROR ".makecellname($row,$col).", $xlsfnin: ".
      ", cell->get_format returned blank. ";
    return ''; # Error, color not found.
    }

return trim($bgcolor); # getcellcolor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant