~ubuntu-branches/ubuntu/intrepid/horae/intrepid

« back to all changes in this revision

Viewing changes to 0CPAN/Spreadsheet-WriteExcel-2.15/examples/date_time.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -w
2
 
 
3
 
###############################################################################
4
 
#
5
 
# Spreadsheet::WriteExcel example of writing dates and times using the
6
 
# write_date_time() Worksheet method.
7
 
#
8
 
# reverse('�'), August 2004, John McNamara, jmcnamara@cpan.org
9
 
#
10
 
 
11
 
use strict;
12
 
use Spreadsheet::WriteExcel;
13
 
 
14
 
 
15
 
# Create a new workbook and add a worksheet
16
 
my $workbook  = Spreadsheet::WriteExcel->new("date_time.xls");
17
 
my $worksheet = $workbook->add_worksheet();
18
 
my $bold      = $workbook->add_format(bold => 1);
19
 
my $row       = 0;
20
 
 
21
 
 
22
 
# Expand the first column so that the date is visible.
23
 
$worksheet->set_column("A:B", 30);
24
 
 
25
 
 
26
 
# Write the column headers
27
 
$worksheet->write('A1', 'Formatted date', $bold);
28
 
$worksheet->write('B1', 'Format',         $bold);
29
 
 
30
 
 
31
 
# Examples date and time formats. In the output file compare how changing
32
 
# the format codes change the appearance of the date.
33
 
#
34
 
my @date_formats = (
35
 
    'dd/mm/yy',
36
 
    'mm/dd/yy',
37
 
    '',
38
 
    'd mm yy',
39
 
    'dd mm yy',
40
 
    '',
41
 
    'dd m yy',
42
 
    'dd mm yy',
43
 
    'dd mmm yy',
44
 
    'dd mmmm yy',
45
 
    '',
46
 
    'dd mm y',
47
 
    'dd mm yyy',
48
 
    'dd mm yyyy',
49
 
    '',
50
 
    'd mmmm yyyy',
51
 
    '',
52
 
    'dd/mm/yy',
53
 
    'dd/mm/yy hh:mm',
54
 
    'dd/mm/yy hh:mm:ss',
55
 
    'dd/mm/yy hh:mm:ss.000',
56
 
    '',
57
 
    'hh:mm',
58
 
    'hh:mm:ss',
59
 
    'hh:mm:ss.000',
60
 
);
61
 
 
62
 
 
63
 
# Write the same date and time using each of the above formats. The empty
64
 
# string formats create a blank line to make the example clearer.
65
 
#
66
 
for my $date_format (@date_formats) {
67
 
    $row++;
68
 
    next if $date_format eq '';
69
 
 
70
 
    # Create a format for the date or time.
71
 
    my $format =  $workbook->add_format(
72
 
                                        num_format => $date_format,
73
 
                                        align      => 'left'
74
 
                                       );
75
 
 
76
 
    # Write the same date using different formats.
77
 
    $worksheet->write_date_time($row, 0, '2004-08-01T12:30:45.123', $format);
78
 
    $worksheet->write          ($row, 1, $date_format);
79
 
}
80
 
 
81
 
 
82
 
# The following is an example of an invalid date. It is written as a string instead
83
 
# of a number. This is also Excel's default behaviour.
84
 
#
85
 
$row += 2;
86
 
$worksheet->write_date_time($row, 0, '2004-13-01T12:30:45.123');
87
 
$worksheet->write          ($row, 1, 'Invalid date. Written as string.', $bold);
88
 
 
89
 
__END__
90