sub createExcel { # Lokale Variaben: my @toDo = @_; my $EVAL_ERROR; my $excel; my $book; my $sheet; showLine(); print "FUNCTION createExcel\n"; print "Try to open Excel.\n"; # falls Instanz von Excel schon läuft benutze diese: eval {$excel = Win32::OLE->GetActiveObject('Excel.Application')}; return 1 if $EVAL_ERROR; #wenn $excel noch nichts zugewiesen starte Excel: unless (defined $excel) { $excel = Win32::OLE->new('Excel.Application') #, sub {$_[0]->Quit;} or return 1; } print "Excel ok.\n"; # Excel sichtbar/unsichtbar machen $excel->{Visible} = 1; # Erzeuge leere Tabelle: $book = $excel->Workbooks->Add; $sheet = $book->Worksheets(1); print "Write to File. \n"; my $length = @toDo; if ($length eq 0) { $sheet->Cells(1,1)->{Value} = "Keine passenden Einträge gefunden!"; } else { for (my $i=0; $i<$length; $i++) { $sheet->Cells($i+1,1)->{Value} = $toDo[$i][0]; $sheet->Cells($i+1,2)->{Value} = $toDo[$i][3]; $sheet->Cells($i+1,3)->{Value} = $toDo[$i][1]; $sheet->Cells($i+1,4)->{Value} = $toDo[$i][2]; $sheet->Cells($i+1,5)->{Value} = $toDo[$i][4]; } } return 0; }