#! /usr/bin/env perl
use warnings;
use 5.012;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new( 'test_test.xls' ) or die $!;
my $sheet = $workbook->add_worksheet();
my $format_in = $workbook->add_format( align => 'center', valign => 'vcenter' );
my $format_st = $workbook->add_format( align => 'center', valign => 'vcenter' );
$format_in->set_num_format ( 'hh:mm' );
$format_st->set_num_format ( '[h]:mm' );
$sheet->set_row( 0, 22 );
$sheet->set_row( 1, 22 );
$sheet->set_column( 'A:D', 20, $format_in );
$sheet->set_column( 'E:E', 20, $format_st );
$sheet->write( 'A1', 'begin am' );
$sheet->write( 'B1', 'end am' );
$sheet->write( 'C1', 'begin pm' );
$sheet->write( 'D1', 'end pm' );
$sheet->write( 'E1', 'time' );
$sheet->data_validation( 'A2:D2', {
validate => 'time',
criteria => 'between',
minimum => 'T06:00',
maximum => 'T20:00',
});
$sheet->write_formula( 'E2', '=(B2-A2)+(D2-C2)' );
$workbook->close() or die $!;
哪种data_validation将检查“end am”值是否大于“begin am”值(先是“end pm”,然后是“begin pm”)?
我试过了,但是没有用:
$sheet->data_validation( 'B2', {
validate => 'time',
criteria => '>=',
value => '=A2',
});
$sheet->data_validation( 'D2', {
validate => 'time',
criteria => '>=',
value => '=C2',
});
Spreadsheet::WriteExcel
最佳答案
您显示的后面的验证应该起作用。请参见下面的屏幕截图:
如果以hh:mm格式输入时间,则应获得相同的效果。
您正在使用哪个版本的Excel?这些数据验证不适用于OpenOffice。
附言我是Spreadsheet::WriteExcel的作者。
关于perl - 试算表:: WriteExcel-data_validation,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4582995/