version 1.4, 2003/05/23 14:52:51
|
version 1.5, 2003/05/23 19:36:04
|
Line 1110 sub calcsheet {
|
Line 1110 sub calcsheet {
|
## Output Helpers |
## Output Helpers |
## |
## |
########################################################### |
########################################################### |
|
sub display { |
|
my $self = shift; |
|
my ($r) = @_; |
|
$self->compute($r); |
|
my $outputmode = 'html'; |
|
if ($ENV{'form.output_format'} =~ /^(html|excel|csv)$/) { |
|
$outputmode = $ENV{'form.output_format'}; |
|
} |
|
if ($outputmode eq 'html') { |
|
$self->outsheet_html($r); |
|
} elsif ($outputmode eq 'excel') { |
|
$self->outsheet_excel($r); |
|
} elsif ($outputmode eq 'csv') { |
|
$self->outsheet_csv($r); |
|
} |
|
return; |
|
} |
|
|
############################################ |
############################################ |
## HTML output routines ## |
## HTML output routines ## |
############################################ |
############################################ |
Line 1212 sub html_row {
|
Line 1230 sub html_row {
|
return $row_html; |
return $row_html; |
} |
} |
|
|
|
sub html_header { |
|
my $self = shift; |
|
return '' if (! $ENV{'request.role.adv'}); |
|
return "<table>\n". |
|
'<tr><th align="center">Output Format</th><tr>'."\n". |
|
'<tr><td>'.&output_selector()."</td></tr>\n". |
|
"</table>\n"; |
|
} |
|
|
|
sub output_selector { |
|
my $output_selector = '<select name="output_format" size="3">'."\n"; |
|
my $default = 'html'; |
|
if (exists($ENV{'form.output_format'})) { |
|
$default = $ENV{'form.output_format'} |
|
} else { |
|
$ENV{'form.output_format'} = $default; |
|
} |
|
foreach (['html','HTML'], |
|
['excel','Excel'], |
|
['csv','Comma Seperated Values']) { |
|
my ($name,$description) = @{$_}; |
|
$output_selector.=qq{<option value="$name"}; |
|
if ($name eq $default) { |
|
$output_selector .= ' selected'; |
|
} |
|
$output_selector .= ">$description</option>\n"; |
|
} |
|
$output_selector .= "</select>\n"; |
|
return $output_selector; |
|
} |
|
|
|
################################################ |
|
## Excel output routines ## |
|
################################################ |
|
sub excel_output_row { |
|
my $self = shift; |
|
my ($worksheet,$rownum,$rows_output,@prepend) = @_; |
|
my $cols_output = 0; |
|
# |
|
my @rowdata = $self->get_row($rownum); |
|
foreach my $cell (@prepend,@rowdata) { |
|
my $value = $cell; |
|
$value = $cell->{'value'} if (ref($value)); |
|
$value =~ s/\ / /gi; |
|
$worksheet->write($rows_output,$cols_output++,$value); |
|
} |
|
return; |
|
} |
|
|
sub create_excel_spreadsheet { |
sub create_excel_spreadsheet { |
my $self = shift; |
my $self = shift; |
my ($r) = @_; |
my ($r) = @_; |
Line 1237 sub create_excel_spreadsheet {
|
Line 1304 sub create_excel_spreadsheet {
|
return ($workbook,$filename); |
return ($workbook,$filename); |
} |
} |
|
|
|
sub outsheet_excel { |
|
my $self = shift; |
|
my ($r) = @_; |
|
$r->print("<h2>Preparing Excel Spreadsheet</h2>"); |
|
# |
|
# Create excel worksheet |
|
my ($workbook,$filename) = $self->create_excel_spreadsheet($r); |
|
return if (! defined($workbook)); |
|
# |
|
# Create main worksheet |
|
my $worksheet = $workbook->addworksheet('main'); |
|
my $rows_output = 0; |
|
my $cols_output = 0; |
|
# |
|
# Write excel header |
|
foreach my $value ($self->get_title()) { |
|
$cols_output = 0; |
|
$worksheet->write($rows_output++,$cols_output,$value); |
|
} |
|
$rows_output++; # skip a line |
|
# |
|
# Write summary/export row |
|
$cols_output = 0; |
|
$self->excel_output_row($worksheet,0,$rows_output++,'Summary'); |
|
$rows_output++; # skip a line |
|
# |
|
$self->excel_rows($worksheet,$cols_output,$rows_output); |
|
# |
|
# |
|
# Close the excel file |
|
$workbook->close(); |
|
# |
|
# Write a link to allow them to download it |
|
$r->print('<br />'. |
|
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
|
return; |
|
} |
|
|
############################################ |
############################################ |
## XML output routines ## |
## XML output routines ## |
############################################ |
############################################ |