Excel::Writer::XLSX pre-release with Chart support

12 views
Skip to first unread message

jmcnamara

unread,
Mar 22, 2011, 4:13:55 PM3/22/11
to Spreadsheet::WriteExcel
Excel::Writer::XLSX pre-release with Chart support

A version of Excel::Writer::XLSX with support for charts is available
for pre-release testing.

The latest version is on the charts branch of the GitHub repo:

https://github.com/jmcnamara/excel-writer-xlsx/tree/charts

Here is an example of a bar chart:

http://homepage.eircom.net/~jmcnamara/perl/images/bar_chart.jpg

There is more of less the same functionality as
Spreadsheet::WriteExcel with a few caveats:

* Only embedded charts are currently supported. Worksheet charts
are coming soon.
* Stock charts don't work correctly.
* set_chartarea() and set_plotarea() don't work.

There is also support for the new Excel 2007 chart styles feature
which allows you to format charts in one of 42 builtin styles:

$chart->set_style( 14 );

New legend positions are also supported.

This sets the groundwork for additional features to be added such as:

* User defined axes ranges.
* Gridlines.
* Formatting.
* Hi-lo lines.
* Droplines.
* Other features.

However, new features, not in the Spreadsheet::WriteExcel API, won't
be added until after at least one CPAN release.

If you are currently using charts in Spreadsheet::WriteExcel and would
care to try it out you can download and install it from the link
above.

This is beta software. You can expect the internals to change but not
the API (apart from a few simplifications).

Try it out and let me know if you encounter any issues.

John.
--


jmcnamara

unread,
Mar 22, 2011, 4:27:28 PM3/22/11
to Spreadsheet::WriteExcel


Just for some background on what is involved in porting a feature like
Charts to Excel::Writer::XLSX.

Github reports 25 commits, 98 files changes (mostly added) and 10,000
lines of code added or modified.

You can see the details here:

https://github.com/jmcnamara/excel-writer-xlsx/compare/master...charts

https://github.com/jmcnamara/excel-writer-xlsx/compare/master...charts#files_bucket

Of the files added there are 80+ test cases. That is significant since
it wouldn't be possible to port a feature like this without that level
of testing. At least it wouldn't be possible to do it with any level
of confidence.

I also wrote some blog posts recently on the "Test Driven Development
of Excel::Writer::XLSX" if anyone is interested in a little more
detail:

http://blogs.perl.org/users/john_mcnamara/2011/02/test-driven-development-of-excelwriterxlsx-part-i.html
http://blogs.perl.org/users/john_mcnamara/2011/02/test-driven-development-of-excelwriterxlsx-part-ii.html
http://blogs.perl.org/users/john_mcnamara/2011/03/test-driven-development-of-excelwriterxlsx-part-iii.html

John.
--

jmcnamara

unread,
Mar 24, 2011, 10:44:39 PM3/24/11
to Spreadsheet::WriteExcel
Hi,

I've implemented standalone chart sheets and pushed the changes to
GitHub:

https://github.com/jmcnamara/excel-writer-xlsx/tree/charts

I'll prepare this for release to CPAN on the weekend. If anyone has
encountered any issues let me know.

Example program showing a chart on a separate sheet:


use strict;
use warnings;
use Excel::Writer::XLSX;

my $workbook = Excel::Writer::XLSX->new( 'chartsheet.xlsx' );
my $worksheet = $workbook->add_worksheet();
my $chart = $workbook->add_chart( type => 'bar' );


my $data = [
[ 1, 2, 3, 4, 5 ],
[ 2, 4, 6, 8, 10 ],
[ 3, 6, 9, 12, 15 ],

];

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

$chart->add_series( values => '=Sheet1!$A$1:$A$5' );
$chart->add_series( values => '=Sheet1!$B$1:$B$5' );
$chart->add_series( values => '=Sheet1!$C$1:$C$5' );

$workbook->close();

John.
--

Reply all
Reply to author
Forward
0 new messages