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; ------------------------------------------------------------------------------- <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <head><title>excel_start</title> <head> <body bgcolor="#fcf5ca"> <h2>excel_start</h2> <a href="http://localhost/index.html">http://localhost/index.html</a> <hr> <form method="POST" action="excel_write.pl"> <center> <table> <tr bgcolor="white"><th>name</th><th>value</th></tr> <TMPL_LOOP NAME="LOOP"> <tr bgcolor="white"><td><TMPL_VAR NAME="name"></td><td><TMPL_VAR NAME="value"></td></tr> <input type="hidden" name="<TMPL_VAR NAME="name">" value="<TMPL_VAR NAME="value">"> </TMPL_LOOP> </table> <input type="submit" value="選択"> </form> </center> <hr> </body> </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__ ------------------------------------------------------------------------------- <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <head><title>excel_write</title> <head> <body bgcolor="#fcf5ca"> <h2>excel_write</h2> <a href="http://localhost/index.html">http://localhost/index.html</a> <hr> 選択結果は次のとおりである。<br> NO1==><TMPL_VAR NAME="NO1"><br> <hr> <a href="http://localhost/scripts/excel_start.pl">戻る</a> </body> </html> ------------------------------------------------------------------------------- 上記のwrite_excelサブルーチンを実行すると,下記のエラーが出る。IISサーバの問題?

プロセスはファイルにアクセスできません。別のプロセスが使用中です。
-------------------------------------------------------------------------------
戻る