Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 90815a31

Von Joachim Zach vor mehr als 14 Jahren hinzugefügt

  • ID 90815a31b45ced8f49c31502cff1c8155e692a7a
  • Vorgänger bedf5ec6
  • Nachfolger 4236c151

Optionale minimale Excel-Unterstützung für Druckvorlagen (Austausch von Platzhalter-Variablen in Excel-Dateien). Entsprechend noch für strict angepasst

Unterschiede anzeigen:

SL/Template.pm
1477 1477
  return 1;
1478 1478
}
1479 1479

  
1480

  
1481
##########################################################
1482
####
1483
#### ExcelTemplate
1484
####
1485
##########################################################
1486

  
1487
package ExcelTemplate;
1488

  
1489
use vars qw(@ISA);
1490

  
1491
@ISA = qw(SimpleTemplate);
1492

  
1493
sub new {
1494
  my $type = shift;
1495

  
1496
  my $self = $type->SUPER::new(@_);
1497

  
1498
  return $self;
1499
}
1500
sub _init {
1501
  my $self = shift;
1502

  
1503
  $self->{source}    = shift;
1504
  $self->{form}      = shift;
1505
  $self->{myconfig}  = shift;
1506
  $self->{userspath} = shift;
1507

  
1508
  $self->{error}     = undef;
1509

  
1510
  $self->set_tag_style('<<', '>>');
1511
}
1512

  
1513
sub get_mime_type() {
1514
  my ($self) = @_;
1515

  
1516
  return "application/msexcel";
1517
}
1518

  
1519
sub uses_temp_file {
1520
  return 1;
1521
}
1522

  
1523
sub parse {
1524
  $main::lxdebug->enter_sub();
1525

  
1526
  my $self   = shift;
1527
  local *OUT = shift;
1528
  my $form   = $self->{"form"};
1529

  
1530
  open(IN, "$form->{templates}/$form->{IN}") or do { $self->{"error"} = "$!"; return 0; };
1531
  my @lines = <IN>;
1532
  close IN;
1533

  
1534
  my $contents = join("", @lines);
1535
  my @indices;
1536
  $contents =~ s{
1537
    $self->{tag_start} [<]* (\s?) [<>\s]* ([\w\s]+) [<>\s]* $self->{tag_end}
1538
  }{
1539
    $self->format_vars(align_right => $1 ne '', varstring => $2, length => length($&), indices =>  \@indices)
1540
  }egx;
1541

  
1542
  if (!defined($contents)) {
1543
    $main::lxdebug->leave_sub();
1544
    return 0;
1545
  }
1546

  
1547
  print OUT $contents;
1548

  
1549
  $main::lxdebug->leave_sub();
1550
  return 1;
1551
}
1552

  
1553
sub format_vars {
1554
  my ($self, %params) = @_;
1555
  my $form            = $self->{"form"};
1556
  my @indices         = @{ $params{indices} };
1557
  my $align_right     = $params{align_right};
1558
  my $varstring       = $params{varstring};
1559
  my $length          = $params{length};
1560

  
1561
  $varstring =~ s/(\w+)/ $self->_get_loop_variable($1, 0, @indices) /eg;
1562
  my $old_string=$varstring;
1563
  my $new_string = sprintf "%*s", ($align_right ? 1 : -1 ) * $length, $varstring;
1564
  if (!defined($new_string) || $new_string eq ''){
1565
    $main::lxdebug->message(0, 'varstring' . $varstring . "old" . $old_string); 
1566
    #  return substr $varstring, ($align_right ? (0, $length) : -$length);
1567
  }
1568
  return substr $new_string, ($align_right ? (0, $length) : -$length);
1569
}
1570

  
1480 1571
1;

Auch abrufbar als: Unified diff