Here is a simple Tk example. I've just put the row-col numbers in the cells, but you could load $cells{$row}{$col}{'data'} with your spreadsheet output and use that for the text. It is also possible to change fonts, cell colors, text color, etc. When you click the png-output button, be patient, it may take a second or 2.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::WinPhoto;
use Tk::PNG;
my $mw = tkinit;
my $width = 500;
my $height = 700;
my $canv = $mw->Canvas(width => $width, height =>$height)->pack();
#set cell size adjustment
my $x = 50;
my $y = 20;
my $rows = int( $height / $y + 1 ) - 1; #make it 0 based
my $cols = int( $width / $x + 1 ) - 1;
print "rows->$rows cols->$cols\n";
my %cells;
foreach my $row ( 0 .. $rows ) {
foreach my $col ( 0 .. $cols ) {
$cells{$row}{$col}{'rect'} = $canv->createRectangle(
$col * $x, $row * $y, $col * $x + $x, $row * $y + $y,
#-width => 1,
-outline => 'white',
);
$cells{$row}{$col}{'text'} = $canv->createText(
$col * $x + $x/2 , $row * $y + $y/2,
-text => "$row - $col",
-anchor => 'center',
-fill => 'black',
);
}
}
my $canvbutton = $mw->Button(-text=>'Canvas Capture',
-command => \&canv_capture,
)->pack;
MainLoop;
##########################################################
sub canv_capture{
my $image = $mw->Photo(-format => 'Window',
-data => oct($canv->id)
);
my $pathname = './canvas.'.time.'.png';
$image->write($pathname, -format => 'PNG');
}
##############################################################
I'm not really a human, but I play one on earth.
flash japh
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.