December 2009 Archives

Spreadsheet::WriteExcel with Charts

In the past I've avoided trying to implement charts in Spreadsheet::WriteExcel because the task always seemed too big to tackle in the time scales that I get to work with.

However, prompted by a module user, I went back to revisit it. The task was still too big but I did it anyway.

So I've uploaded version 2.32 of Spreadsheet::WriteExcel to CPAN. Here is the documentation for Charts and here is an example.

#!/usr/bin/perl -w

use strict;
use Spreadsheet::WriteExcel;

my $workbook  = Spreadsheet::WriteExcel->new( 'chart.xls' );
my $worksheet = $workbook->add_worksheet();

my $chart     = $workbook->add_chart( name => 'Chart1', type => 'line' );

# Configure the chart.
    categories => '=Sheet1!$A$2:$A$7',
    values     => '=Sheet1!$B$2:$B$7',

# Add the data to the worksheet the chart refers to.
my $data = [
    [ 'Category', 2, 3, 4, 5, 6, 7 ],
    [ 'Value',    1, 4, 5, 2, 1, 5 ],

$worksheet->write( 'A1', $data );

Here is a slightly longer example from the distro.

There is still plently of work to be done but it is a good start.


Some Perl one-liners

In response to brian d foy's post looking for the best Perl one-liners you've written I dug out my one liners file that I occasionally update.

I wouldn't say that many of these count in the "best" category, some of the tasks can be accomplished with system utilities and some are obfuscated or golfed. But I find it useful to keep these around to remind me of solutions that I might otherwise forget or have to re-invent.

So with those provisos here they are:


Uploading to CPAN from GitHub

It only works if your git working copy is structured the same way as the tarball that you want to upload to CPAN. So, if you are making heavy use of MANIFEST.SKIP this probably won't work for you (unless you are also git-ignoring those files). You will also have to ensure that the version number in META.yml in incremented (I've generally rely on ExtUtils::MakeMake…

About John McNamara

user-pic Just another Perl hacker