[Bio] / FigKernelPackages / raelib.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/raelib.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38, Mon Jun 19 21:19:22 2006 UTC revision 1.39, Tue Jun 20 03:34:43 2006 UTC
# Line 1004  Line 1004 
1004    
1005      for my $i (0 .. $#$col_hdrs)      for my $i (0 .. $#$col_hdrs)
1006      {      {
1007          my $cell=$self->clean_excel_cell($col_hdrs->[$i]);          my $cell;
1008            my ($useformat, $rowspan, $colspan);
1009            if (ref($col_hdrs->[$i]) eq "ARRAY") {($cell, $useformat, $rowspan, $colspan)=$self->parse_cell($col_hdrs->[$i])}
1010            else  {$cell=$col_hdrs->[$i]}
1011            my $cell=$self->clean_excel_cell($cell);
1012          $worksheet->write(0, $i, $cell, $self->{'excel_format'}->{header});          $worksheet->write(0, $i, $cell, $self->{'excel_format'}->{header});
1013      }      }
1014    
1015      # now loop through the table and write them out. Remember to break on array refs      # now loop through the table and write them out. Remember to break on array refs
1016        # we are going to have to build the table col by col so we get the breaks in the right place
1017        # for merged cells
1018      my $row_idx=1;      my $row_idx=1;
1019      my $col_idx=0;      my $maxrow=$#$tab;
1020      foreach my $row (@$tab)      my $skip;
1021        while ($row_idx <= $maxrow+1)
1022      {      {
1023          foreach my $cell (@$row)          my @row=@{$tab->[$row_idx-1]};
1024            my $col_idx=0;
1025            foreach my $cell (@row)
1026          {          {
1027                while ($skip->{$row_idx}->{$col_idx}) {$col_idx++}
1028              my $useformat=$self->{'excel_format'}->{default};              my $useformat=$self->{'excel_format'}->{default};
1029    
1030              # there is an approach to setting color using \@bgcolor. Oh well.              # there is an approach to setting color using \@bgcolor. Oh well.
# Line 1023  Line 1033 
1033                  $cell=[$2, $1];                  $cell=[$2, $1];
1034              }              }
1035    
1036                my ($rowspan, $colspan);
1037              if (ref($cell) eq "ARRAY")              if (ref($cell) eq "ARRAY")
1038              {              {
1039                  ($cell, $useformat)=$self->parse_cell($cell);                  ($cell, $useformat, $rowspan, $colspan)=$self->parse_cell($cell);
1040              }              }
1041    
1042              $cell=$self->clean_excel_cell($cell);              $cell=$self->clean_excel_cell($cell);
1043    
1044                if ($rowspan > 1 || $colspan > 1)
1045                {
1046                    # handle merged cells separately
1047                    my $row_idx_to=$row_idx+$rowspan-1;
1048                    my $col_idx_to=$col_idx+$colspan-1;
1049                    # we want to not put anything in the merged cells
1050                    for (my $x=$row_idx; $x<=$row_idx_to; $x++) {$skip->{$x}->{$col_idx}=1}
1051                    for (my $y=$col_idx; $y<=$col_idx_to; $y++) {$skip->{$row_idx}->{$y}=1}
1052    
1053                    if (ref($cell) eq "ARRAY") {$worksheet->merge_range($row_idx, $col_idx, $row_idx_to, $col_idx_to, @$cell, $useformat)}
1054                    else {$worksheet->merge_range($row_idx, $col_idx, $row_idx_to, $col_idx_to, $cell, $useformat)}
1055                }
1056                else
1057                {
1058              # this is a botch, but in some circumstances we need to split the cell out. e.g. if it is a URL              # this is a botch, but in some circumstances we need to split the cell out. e.g. if it is a URL
1059              # in this case we have a reference to an array, and we'll use  a slight modification on the process              # in this case we have a reference to an array, and we'll use  a slight modification on the process
1060                    if ((ref($cell) eq "ARRAY" && $cell->[0] eq " &nbsp; ") || $cell eq " &nbsp; ") {$worksheet->write_blank($row_idx, $col_idx, $useformat)}
1061                    else
1062                    {
1063              if (ref($cell) eq "ARRAY") {$worksheet->write($row_idx, $col_idx, @$cell, $useformat)}              if (ref($cell) eq "ARRAY") {$worksheet->write($row_idx, $col_idx, @$cell, $useformat)}
1064              else {$worksheet->write($row_idx, $col_idx, $cell, $useformat)}              else {$worksheet->write($row_idx, $col_idx, $cell, $useformat)}
1065                    }
1066                }
1067    
1068              # increment to the next column              # increment to the next column
1069              $col_idx++;              $col_idx++;
# Line 1094  Line 1125 
1125      # we are going to define a series of formats that we can apply, this will have  a key that is      # we are going to define a series of formats that we can apply, this will have  a key that is
1126      # th.center.bgcolor.fgcolor. Then if we already have that, we can use it, if not, we'll define it      # th.center.bgcolor.fgcolor. Then if we already have that, we can use it, if not, we'll define it
1127    
1128      my ($th, $center, $bgcolor, $fgcolor)=(undef, undef, undef, undef);      my ($th, $center, $bgcolor, $fgcolor)=(0,0,0,0);
1129    
1130      if ($tag =~ /^th/) {$th=1} # it is a header cell so we should make it bold      if ($tag =~ /^th/) {$th=1} # it is a header cell so we should make it bold
1131      if ($tag =~ /align\=\"(.*?)\"/i) {$center=$1}      if ($tag =~ /align\=\"(.*?)\"/i) {$center=$1}
# Line 1132  Line 1163 
1163          $fgcolor=$self->{'excel_color'}->{$color};          $fgcolor=$self->{'excel_color'}->{$color};
1164      }      }
1165    
1166      if (!defined $self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor})      # check and see if we span multiple rows or columns
1167        my ($rowspan, $colspan)=(1,1);
1168        if ($tag =~ /rowspan\=[\'\"]?(\d+)/) {$rowspan=$1} # these should match rowspan="4", rowspan='4', and rowspan=4
1169        if ($tag =~ /colspan\=[\'\"]?(\d+)/) {$colspan=$1}
1170    
1171        my $formatid=$th.$center.$bgcolor.$fgcolor.$rowspan.$colspan;
1172        if (!defined $self->{'excel_format'}->{$formatid})
1173        {
1174            $self->{'excel_format'}->{$formatid}=$self->{'excel_workbook'}->add_format();
1175            if ($rowspan > 1) {$self->{'excel_format'}->{$formatid}->set_align("vcenter")}
1176            else
1177      {      {
1178          $self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor}=$self->{'excel_workbook'}->add_format();              if ($th) {$self->{'excel_format'}->{$formatid}->copy($self->{'excel_format'}->{header})}
1179          if ($th) {$self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor}->copy($self->{'excel_format'}->{header})}              else {$self->{'excel_format'}->{$formatid}->copy($self->{'excel_format'}->{default})}
1180          else {$self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor}->copy($self->{'excel_format'}->{default})}          }
1181          $center && $self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor}->set_align($center);          $center && $self->{'excel_format'}->{$formatid}->set_align($center);
1182          $bgcolor && $self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor}->set_bg_color($bgcolor);          $bgcolor && $self->{'excel_format'}->{$formatid}->set_bg_color($bgcolor);
1183          $fgcolor && $self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor}->set_color($fgcolor);          $fgcolor && $self->{'excel_format'}->{$formatid}->set_color($fgcolor);
1184      }      }
1185    
1186      return ($cell, $self->{'excel_format'}->{$th.$center.$bgcolor.$fgcolor});      return ($cell, $self->{'excel_format'}->{$formatid}, $rowspan, $colspan);
1187  }  }
1188    
1189    

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3