Perl data labels of chart in excel -
i'm struggling problem more or less 2 days , i'm frustrated, since problem not big algorithm... want write perl program, saves few values excel sheet , makes xlcolumnstacked100 labeled diagram specific column colors out of it. far, managed make either stacked diagram (win32::ole) or labeled 1 (excel::writer::xlsx). doing wrong?? tried many things, somehow never has be... in advance tips!
#!/usr/bin/perl -w use warnings; use win32::ole; use win32::ole qw(in); use win32::ole::const 'microsoft excel'; use win32::ole::const 'microsoft office .* object library'; use diagnostics; use strict; $xlapp = win32::ole->new('excel.application'); $xlapp->{visible} = 1; $xlbook = $xlapp->workbooks->add; $mydata = [["", "a", "b", "c", "d", "e"], ["x", "1", "2", "3", "4", "5"], ["y", "2", "3", "4", "5", "6"], ["z", "3", "4", "5", "6", "7"], ]; $rng = $xlbook->activesheet->range("a1:f4"); $rng->{value} = $mydata; $chart = $xlbook->charts->add; $chart->setsourcedata($rng, 2); $chart->{charttype} = 53; $chart->location(2, "tabelle1"); $xlapp->$xlbook->$chart->applydatalabels({autotext => 1});
the other code:
#!/usr/bin/perl use strict; use warnings; use diagnostics; use excel::writer::xlsx; $workbook = excel::writer::xlsx->new('c:\\diagramm.xlsx'); $worksheet = $workbook->add_worksheet(); $bold = $workbook->add_format( bold => 1 ); $headings = [ ' ', 'a', 'b', 'c', 'd', 'e']; $data = [ ['x', 'z', 'y'], [1, 2, 3], [2, 3, 43], [3, 4, 5], [4, 5, 6], [5, 6, 7], ]; $worksheet->write( 'a1', $headings, $bold ); $worksheet->write( 'a2', $data ); $chart = $workbook->add_chart( type => 'column', embedded => 1 ); $chart->add_series( categories => '=sheet1!$a$2:$a$4', values => '=sheet1!$b$2:$b$4', data_labels => { value => 1 }, name => 'a', ); $chart->add_series( categories => '=sheet1!$a$2:$a$4', values => '=sheet1!$c$2:$c$4', data_labels => { value => 1 }, name => 'b', ); $chart->add_series( categories => '=sheet1!$a$2:$a$4', values => '=sheet1!$d$2:$d$4', data_labels => { value => 1 }, name => 'c', ); $chart->add_series( categories => '=sheet1!$a$2:$a$4', values => '=sheet1!$e$2:$e$4', data_labels => { value => 1 }, name => 'd', ); $chart->add_series( categories => '=sheet1!$a$2:$a$4', values => '=sheet1!$f$2:$f$4', data_labels => { value => 1 }, name => 'e', ); $chart->set_x_axis( name => 'somename' ); $chart->set_title( name => 'sometitle' ); $chart->set_style( 10 ); $worksheet->insert_chart( 'j2', $chart, 25, 10 );
Comments
Post a Comment