Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Excel in Perl/Tk

by vsurend (Novice)
on Sep 21, 2011 at 08:43 UTC ( #927097=perlquestion: print w/ replies, xml ) Need Help??
vsurend has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have created Excel using Spreadsheet::WriteExcel in Perl/Tk. The created xls is getting save to the location where my program resides. I want to Open an excel instead of saving it first itself. And the User should save the excel to the system only if required. Can you please help how can I do that. -Vidya

Comment on Excel in Perl/Tk
Re: Excel in Perl/Tk
by Tux (Monsignor) on Sep 21, 2011 at 08:53 UTC

    You could use Tk::TableMatrix::Spreadsheet to present your spreadsheet to the user and add a button "Save" to store it as you do now.

    my $ss = $mw->Scrolled ('Spreadsheet', -rows => $h, -cols => $w, -width => 10, -height => 20, -titlerows => 1, -titlecols => 0, -selectmode => "extended", -resizeborders => "both", -justify => "left", -anchor => "w", -variable => $data, )->pack (-expand => 1, -fill => "both", -side => "top", -anchor => + "nw"); $ss->Subwidget ("${_}scrollbar")->configure (-width => 6) for qw( x y +); $ss->tagConfigure ("title", -bg => "#ffffe0", -justify => "left"); $ss->tagConfigure ("active", -bg => "#ffff40", -justify => "left"); $ss->tagConfigure ("sel", -bg => "gray95", -justify => "left"); # autosize columns on data (not on headers) $ss->colWidth (map { $_ => $w[$_] } 0 .. $#w);

    Enjoy, Have FUN! H.Merijn
Re: Excel in Perl/Tk
by vsurend (Novice) on Sep 21, 2011 at 11:55 UTC
    Can't call method "Scrolled" on an undefined value Getting this error with the code metioned. Can you please help.

      Are you aware that Tux did not provide a complete program? What steps have you taken to determine what the problem is?

Re: Excel in Perl/Tk
by zentara (Archbishop) on Sep 21, 2011 at 13:41 UTC
    Here is a working Tk Spreadsheet. You will need to somehow export your excel data to csv ( or something similar) to fill the data in. See display excel with Perl Tk or google for display excel Perl Tk

    A good example of Tk's spreadsheet, you will need to export your excel data to csv, tsv, or arrays of data.

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::TableMatrix; use Tk::TableMatrix::Spreadsheet; my $top = MainWindow->new; my $arrayVar = {}; print "Filling Array...\n"; my ($rows,$cols) = (40000, 10); foreach my $row (0..($rows-1)){ $arrayVar->{"$row,0"} = "$row"; } foreach my $col (0..($cols-1)){ $arrayVar->{"0,$col"} = "$col"; } print "Creating Table...\n"; sub colSub{ my $col = shift; return "OddCol" if( $col > 0 && $col%2) ; } my $label = $top->Label(-text => "TableMatrix v2 Example") ->pack( -expand => 1, -fill => 'both'); my $t = $top->Scrolled('Spreadsheet', -rows => $rows, -cols => $cols, -width => 6, -height => 12, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -coltagcommand => \&colSub, -colstretchmode => 'last', -flashmode => 1, -flashtime => 2, -wrap=>1, -rowstretchmode => 'last', -selectmode => 'extended', -selecttype=>'cell', -selecttitles => 0, -drawmode => 'slow', -scrollbars=>'se', -sparsearray=>0 )->pack(-expand => 1, -fill => 'both'); #my $realmatrix = $t->Subwidget('scrolled'); $top->Button( -text => "Show Selected", -command => sub{ print $t->curselection(),"\n"; })->pack(-expand => 1, -fill => 'x'); $top->Button( -text => "Clear", -command => sub{&clear})->pack(-expand => 1, -fill => 'x'); $top->Button( -text => "Fill", -command => sub{&fill})->pack(-expand => 1, -fill => 'x'); $top->Button( -text => "Exit", -command => sub{$top->destroy})->pack(-expand => 1, -fill => 'x' +); $t->colWidth( -2 => 8, -1 => 9, 0=> 12, 4=> 14); $arrayVar->{"1,1"} = 42; Tk::MainLoop; ###################################################################### +#### sub TMRefresh { #Required input TableMatrix object. #use to force matrix to update, a code trick return if (!$_[0]); $_[0]->configure(-padx =>($_[0]->cget(-padx))); #$realmatrix->update; #$t->update; #$top->update; #$t->see("100,100"); #trick to force update? #$t->see("end"); #$t->see("1,1"); } ###################################################################### +### sub clear{ #$t->clearAll('0,0','end'); foreach my $row(1..$rows){ foreach my $col(1..$cols){ $arrayVar->{"$row,$col"} = 0; } } &TMRefresh($t); } ###################################################################### +#### sub fill{ foreach my $row(1..$rows){ foreach my $col(1..$cols){ $arrayVar->{"$row,$col"} = 1000; } } &TMRefresh($t); } ###################################################################### +#####

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      My Spreadsheet::Read comes with ss2tk in the examples folder, which displays all spreadsheets supported by Spreadsheet::Read in perl/Tk.

      $ ss2tk --help usage: ss2tk [-w <width>] [X11 options] file.xls [<pattern>] -w <width> use <width> as default column width (4)

      Enjoy, Have FUN! H.Merijn

        Hi All, I have now the data written to my excel sheet. The excel sheet is directly getting saved to my folder when I click the Generate Report button. Can I have the excel sheet opened directly while clicking the button, instead of saving to my local, and to save only if I need to do it. Is there an option for the same. Please help. Thanks, Vidya

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://927097]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-04 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls