File: write_to_scalar.pl

package info (click to toggle)
libexcel-writer-xlsx-perl 0.79-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,716 kB
  • ctags: 930
  • sloc: perl: 18,380; makefile: 40
file content (37 lines) | stat: -rw-r--r-- 876 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl

##############################################################################
#
# An example of writing an Excel::Writer::XLSX file to a perl scalar.
#
# reverse ('(c)'), September 2004, John McNamara, jmcnamara@cpan.org
#

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

# Use a scalar as a filehandle.
open my $fh, '>', \my $str or die "Failed to open filehandle: $!";


# Spreadsheet::WriteExce accepts filehandle as well as file names.
my $workbook  = Excel::Writer::XLSX->new( $fh );
my $worksheet = $workbook->add_worksheet();

$worksheet->write( 0, 0, 'Hi Excel!' );

$workbook->close();


# The Excel file in now in $str. Remember to binmode() the output
# filehandle before printing it.
open my $out_fh, '>', 'write_to_scalar.xlsx'
  or die "Failed to open out filehandle: $!";

binmode $out_fh;
print   $out_fh $str;
close   $out_fh;

__END__