use strict; use warnings; use Tk; use threads; my $thr; my $mainWindow = MainWindow->new; my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7, -scrollbars=>"ose", -wrap=>"word")->pack(); my $goBut = $mainWindow->Button(-foreground=>"blue", -text=>"Click", -command=>sub { $thr = threads->new(\&excecute) } )- >pack(); my $stopBut = $mainWindow->Button(-foreground=>"red", -text=>"Exit", -command=>sub{ if(defined($thr)){ $thr->detach; } exit; })->pack(); MainLoop; sub excecute { $goBut->configure(-state=>"disabled"); $textBox->configure(-state=>"normal"); open(FILE,"C:/file.txt") or die "Can't open file.\n"; while() { my $message = $_; $textBox->insert('end', $message); } close(FILE); $textBox->configure(-state=>"disabled"); $textBox->see('end'); use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my ($Excel,$Workbook,$fileOutput,$CurrentSheet,$Range); $fileOutput = "C:/test.xls"; $Excel = Win32::OLE->new('Excel.Application', 'Quit') || die "Can't create Excel object. \n"; $Excel->{'Visible'} = 1; #0 is hidden, 1 is visible $Excel->{DisplayAlerts} = 0; #0 is hide alerts $Excel->{SheetsInNewWorkbook} = 1; $Workbook = $Excel->Workbooks->Add(); $Workbook->SaveAs($fileOutput) or die "Can't save Excel.\n"; $CurrentSheet = $Workbook->Worksheets(1); $CurrentSheet->Select; for (my $i=1; $i<=65356; $i++) { $Range = $CurrentSheet->Range("A$i"); $Range->{Value} = $i; sleep(0.01); } $Workbook->Save(); $Workbook->Close(); $Excel->Quit(); Win32::OLE->FreeUnusedLibraries(); $goBut->configure(-state=>"normal"); return;