CGI プログラム14
戻る
#!C:/perl/bin/perl
# excel_start.pl
# 07.11.27
use strict;
use HTML::Template;
my (%t,@loop,$n);
# ループデータ生成
@loop = ();
for $n ( 1 .. 30 ) {
$t{name} = 'NO' . $n;
$t{value} = $n + 100;
my %row = (
name => $t{name},
value => $t{value}
);
# put this row into the loop by reference
push(@loop, \%row);
}
# HTMLファイル出力
$t{template} = HTML::Template->new(filename => 'excel_start.htm');
$t{template}->param(LOOP => \@loop);
print $t{template}->output;
1;
-------------------------------------------------------------------------------
excel_start
excel_start
http://localhost/index.html
-------------------------------------------------------------------------------
#!C:/perl/bin/perl
# excel_write.pl
# 07.11.27
use strict;
use CGI qw/:standard/;
use HTML::Template;
my (%t,$n,$e_ref);
# CGIのパラメータ転送
$t{q} = new CGI;
for $n ( 1 .. 30 ) {
$t{name} = 'NO' . $n;
$t{$t{name}} = $t{q}->param($t{name});
}
# Excel ファイルに出力
#($e_ref) = write_excel($e_ref);
# HTMLファイル出力
$t{template} = HTML::Template->new(filename => 'excel_write.htm');
$t{template}->param(NO1 => $t{NO1});
print $t{template}->output;
sub write_excel {
my($e_ref) = @_;
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
use Encode; # set perl's OLE module to return Unicode
my(%t);
# Get the object
$t{ex} = Win32::OLE->new('Excel.Application') or die "oops\n";
$t{ex}->{DisplayAlerts} = 'False';
# open the sample file map.xls
$t{book} = $t{ex}->Workbooks->Open("C:\\TEMP\\map.xls");
# write to a particular cell
$t{sheet} = $t{book}->Worksheets('Sheet1');
# EXCELファイルにデータを書き込む
$t{NO1} = 'That is a test';
$t{sheet}->Cells(3,2)->{'Value'} = $t{NO1};
# Save the excel file
system("del C:\\TEMP\\map1.xls");
$t{book}->SaveAs("C:\\TEMP\\map1.xls");
undef $t{book};
undef $t{ex};
return($e_ref);
}
1;
__END__
-------------------------------------------------------------------------------
excel_write
excel_write
http://localhost/index.html
選択結(jié)果は次のとおりである。
NO1==>
戻る
-------------------------------------------------------------------------------
上記のwrite_excelサブルーチンを?qū)g行すると,下記のエラーが出る。IISサーバの問題?

プロセスはファイルにアクセスできません。別のプロセスが使用中です。
-------------------------------------------------------------------------------
戻る
石林|
南陵县|
营山县|
朝阳市|
达州市|
祁门县|
元朗区|
专栏|
固镇县|
榆中县|
吉安市|
斗六市|
原阳县|
广水市|
五峰|
讷河市|
理塘县|
开鲁县|
全州县|
遵义县|
正宁县|
仙游县|
鸡东县|
汨罗市|
宽城|
永安市|
通城县|
思南县|
策勒县|
涞水县|
光泽县|
五大连池市|
吉林省|
巩义市|
上蔡县|
察隅县|
鄂温|
宜良县|
昭通市|
广丰县|
镇坪县|