Leser: 3
4 Einträge, 1 Seite |
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 38 39 40
#!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new('c:\test.xls'); my $worksheet = $workbook->addworksheet(); my $format1 = $workbook->addformat(); my $format2 = $workbook->addformat(); my $format3 = $workbook->addformat(); my $format4 = $workbook->addformat(); my $format5= $workbook->addformat(); my $format6 = $workbook->addformat(); my $format7 = $workbook->addformat(); my $format8 = $workbook->addformat(); my @cell_format = ( 'TEXT', 'STANDARD', '#.##', '#.## ¤', '#.## ¤ / # ¤', 'PLZ', 'TT.MM.JJJJ', 'TT.MM.JJ' ); $format1->set_num_format('@'); $format2->set_num_format('0'); $format3->set_num_format('0.00'); $format4->set_num_format('0.00 ¤'); $format5->set_num_format('0 ¤'); $format6->set_num_format('00000'); $format7->set_num_format('dd.mm.yyyy'); $format8->set_num_format('dd.mm.yy'); my $i = -1; $worksheet->write(0, $i++, $_) for (@cell_format); $worksheet->write_string(1, 0, '0123', $format1); $worksheet->write_number(1, 1, '0123', $format2); $worksheet->write(1, 2, '0123', $format3); $worksheet->write(1, 3, '0123', $format4); $worksheet->write(1, 4, '0123', $format5); $worksheet->write(1, 5, '01234', $format6); $worksheet->write(1, 6, '22.6.1980', $format7); $worksheet->write(1, 7, '1.12.1900', $format8); $workbook->close();
Quote$format07->set_num_format('mm/dd/yy');
$worksheet->write(6, 0, 36892.521, $format07); # 01/01/01
$format08->set_num_format('mmm d yyyy');
$worksheet->write(7, 0, 36892.521, $format08); # Jan 1 2001
$format09->set_num_format('d mmmm yyyy');
$worksheet->write(8, 0, 36892.521, $format09); # 1 January 2001
QuoteDates and times in Excel are represented by real numbers, for example "Jan 1 2001 12:30 AM" is represented by the number 36892.521.
The integer part of the number stores the number of days since the epoch and the fractional part stores the percentage of the day.
...
See also the Spreadsheet::WriteExcel::Utility module that is included in the distro and which includes date handling functions and the DateTime::Format::Excel module, http://search.cpan.org/search?dist=DateTime-Format-Excel which is part of the DateTime project and which deals specifically with converting dates and times to and from Excel's format.
1 2 3 4 5
my $date_str1 = '22.6.1980'; my $date_str2 = '2.12.1901'; $worksheet->write(1, 6, sprintf('%02d.%02d.%4d', split(/\./, $date_str1)), $format7); $worksheet->write(1, 7, sprintf('%02d.%02d.%2d', split(/\./, $date_str2)), $format8);
4 Einträge, 1 Seite |