#!/usr/bin/perl -w
use strict;
use cmj_date;
use Spreadsheet::WriteExcel;
# Variables
my $file_name = 'switch_report.xls';
my $hash_ref = shift;
#temp for development
#set year to 2002.
my $month = '07';
my $year = '2002';
####
my %switch_hash = (
chrdex => {
'01-AUG-02' => 1,
'03-AUG-02' => 3,
},
uslcgb5e2sm => {
'4-AUG-02' => 1,
'6-AUG-02' => 2,
},
uslecat2531 => {
'1-AUG-02' => 1,
'2-AUG-02' => 3,
'3-AUG-02' => 1,
'4-AUG-02' => .25,
},
);
####
my $rswitch_hash = \%switch_hash;
my %calendar = (
JAN => 31,
FEB => 28,
MAR => 31,
APR => 30,
MAY => 31,
JUN => 30,
JUL => 31,
AUG => 31,
SEP => 30,
OCT => 31,
NOV => 30,
DEC => 31,);
if (! $year % 4 ) {$calendar{FEB} = '29'}; #leap year clause
my $sheet_title= sub { return "Traffic Estimations Report - $_[0] $_[1]" } ;
# Create a new Excel workbook
my $workbook = Spreadsheet::WriteExcel->new($file_name);
# Add a worksheet
my $worksheet = $workbook->addworksheet();
$worksheet->fit_to_pages(1,1);
$worksheet->set_landscape();
$worksheet->set_margins(.25);
$worksheet->set_zoom(75);
#$worksheet->set_column(0,100,12);
# Add formats
my $cb_format = $workbook->addformat(
bold => 1,
italic => 1,
underline => 1,
align => 'center',
size => 26,);
my $rotation_format = $workbook->addformat(
rotation => 2,
bold => 1,
valign => 'vcenter',
align => 'center',
size => 20);
my $clli_format = $workbook->addformat(
align => 'center',);
my $hours_format = $workbook->addformat(
align => 'center');
# Write Day of the month header to the worksheet.
# written rotated 90 degrees counterclockwise
# in vertically merged cells.
$worksheet->write(5,0,"Day of the month",$rotation_format);
$worksheet->merge_cells(5,0,38,0);
$worksheet->set_column(0,0,8.43);
$worksheet->set_column(3,38,11.29);
# write_switch_data
write_hash_data($rswitch_hash);
sub write_hash_data{
my $row = 6;
my $col = 3;
my ($hent) = @_;
my $switch;
my ($day, $month, $year);
# Write switch name and data column for each switch
foreach $switch (sort keys %$hent ) {
$worksheet->write($row, $col, $switch,$clli_format);
foreach my $data (keys %{$$hent{$switch}} ) {
($day, $month, $year) = split("-",$data);
$worksheet->write($row + $day, $col,$$hent{$switch}{$data},$hours_format);
}
$col++; # incriment the column count so the data
} # moves across the page.
# Write Title to the worksheet
$worksheet->write(0,1,&$sheet_title($month, "20".$year), $cb_format);
$worksheet->merge_cells(0,1,2,29);
$worksheet->merge_cells(4,1,4,29);
$worksheet->set_row(4,30.75);
# Write Days/Dates
$row = 7;
$col = 1;
my $count = 1;
my $col_width=1;
while ($count <= $calendar{$month} ) {
my $day_of_week=day_of_week($count."-".$month."-20".$year);
$worksheet->write($row, $col, $day_of_week);
$worksheet->set_column($col,$col, 14.86);
$worksheet->write($row, $col + 1, $count, $hours_format);
$worksheet->set_column($col + 1,$col + 1, 7.57);
$col_width=length($month." ".$count." 20".$year);
$row++;
$count++;
};
};
sub USEAGE{
print "ERROR:\n";
print "Useage: xcl2.pl <4 digit year>\n";
exit;
}