免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3321 | 回复: 3
打印 上一主题 下一主题

请教一个关于CGI perl 调用Excel 数据分析工具的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-04 23:09 |只看该作者 |倒序浏览
函数calc_XXX 在windows 系统下直接进行运行(C:\Users\LF>perl test_1.pl)是可以的,但是在用IE打开相应CGI页面时就会报错,错误日志如下:

[Mon Jun 04 22:33:59 2012] [error] [client 127.0.0.1] Premature end of script headers: qynjjjyjpjhsgj.cgi, referer: http://127.0.0.1/cgi-bin/qynjjjyjpjhsgj.cgi
[Mon Jun 04 22:33:59 2012] [error] [client 127.0.0.1] OLE exception from "Microsoft Office Excel":, referer: http://127.0.0.1/cgi-bin/qynjjjyjpjhsgj.cgi
[Mon Jun 04 22:33:59 2012] [error] [client 127.0.0.1] , referer: http://127.0.0.1/cgi-bin/qynjjjyjpjhsgj.cgi
[Mon Jun 04 22:33:59 2012] [error] [client 127.0.0.1] \xb2\xbb\xc4\xdc\xc8\xa1\xb5\xc3\xc0\xe0 AddIns \xb5\xc4 Add \xca\xf4\xd0\xd4, referer: http://127.0.0.1/cgi-bin/qynjjjyjpjhsgj.cgi
[Mon Jun 04 22:33:59 2012] [error] [client 127.0.0.1] , referer: http://127.0.0.1/cgi-bin/qynjjjyjpjhsgj.cgi
[Mon Jun 04 22:33:59 2012] [error] [client 127.0.0.1] Win32::OLE(0.1709) error 0x800a03ec, referer: http://127.0.0.1/cgi-bin/qynjjjyjpjhsgj.cgi
[Mon Jun 04 22:33:59 2012] [error] [client 127.0.0.1]     in METHOD/PROPERTYGET "Add" at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/qynjjjyjpjhsgj.cgi line 1427, referer: http://127.0.0.1/cgi-bin/qynjjjyjpjhsgj.cgi

系统出错的行是:
  
  $excel->AddIns->Add( "$xll_path" );

主要的目的就是想用CGI调用Excel , 其实后台调用Excel数据分析器进行数据计算。
请问大家遇到过这个问题吗?



详细代码如下:sub calc_XXX {

  my $lib_root = catfile( $ENV{ProgramFiles},
  'Microsoft Office', qw(OFFICE12 Library Analysis) );

  #print "1---$lib_root\n";
  my $xll_path = catfile $lib_root, 'ANALYS32.XLL';
  #print "2---$xll_path\n";
  my $xla_path = catfile $lib_root, 'ATPVBAEN.XLAM';
  #print "3---$xla_path\n";

  my $excel = get_excel();
  #$excel->{Visible} = 1;

  #sleep(5);
  my $book = $excel->Workbooks->Open($JSGCB_13);
  $book->RunAutoMacros(1);

  my $sheet = $book->Worksheets(1);
  
  # count the data line num
  my $flag_counter = -1;
  my $row = 5;
  
  # for calc the line num
  while ($flag_counter ne '0') {
    $flag_counter = 0;
    # check column 1 for the existing line
    if (defined $sheet->Cells($row,1)->{'Value'}) {     
      $flag_counter ++;
    } else {
      last;
    }   
    $row ++;
  }
  
  my $row_num = $row - 1;
  
  my $str_1_1 = '$AQ$5AQ$'.$row_num;
  my $str_1_2 = '$AU$5AV$'.$row_num;
  
  my $str_2_1 = '$AQ$5AQ$'.$row_num;
  my $str_2_2 = '$AS$5AT$'.$row_num;
  
  my $str_3_1 = '$AQ$5AQ$'.$row_num;
  my $str_3_2 = '$AR$5AS$'.$row_num;
  
  
  $excel->AddIns->Add( "$xll_path" );
  $excel->RegisterXLL( 'Analys32.xll' );

  my $atp_book = $excel->Workbooks->Open( $xla_path );
  $atp_book->RunAutoMacros(1);
  $sheet = $book->Worksheets(1);
  #sleep(5);
  # Application.Run "ATPVBAEN.XLA!Regress", ActiveSheet.Range(Cells(2, 2), Cells(i, 2)), ActiveSheet.Range(Cells(2, 3), Cells(i, j)), False, False, , ActiveSheet.Range("$H$26", False, False, False, False, , False


  # for C-L         
  $excel->Run(qq{ATPVBAEN.XLAM!Regress},
            $sheet->Range($str_1_1),
            $sheet->Range($str_1_2),
            0,0,95,'C-L',1,1,1,1,1,1);            
  # for H-M         
  $excel->Run(qq{ATPVBAEN.XLAM!Regress},
            $sheet->Range($str_2_1),
            $sheet->Range($str_2_2),
            0,0,95,'H-M',1,1,1,1,1,1);
  # for T-M
  $excel->Run(qq{ATPVBAEN.XLAM!Regress},
            $sheet->Range($str_3_1),
            $sheet->Range($str_3_2),
            0,0,95,'T-M',1,1,1,1,1,1);
            
  $excel->{DisplayAlerts} = 0;
  if (-e $JSGCB_14) {
    unlink $JSGCB_14;
  }
  #sleep(5);
  # save and exit
  $book->SaveAs($JSGCB_14);
  $book->close;
  undef $book;
  undef $excel;   

  #system ('cmd');
  #exec 'cmd';
}

论坛徽章:
0
2 [报告]
发表于 2012-06-05 09:27 |只看该作者
You should print the HTTP header before any other output.
use CGI;
my $q=CGI->new;
print $q->header;

论坛徽章:
0
3 [报告]
发表于 2012-06-05 09:45 |只看该作者
Thanks for your help!

I have printed the HTTP header in the main sub~

回复 2# 兰花仙子


   

论坛徽章:
0
4 [报告]
发表于 2012-07-04 12:04 |只看该作者
问题解决了, 环境变量的问题,使用cgi后path环境变量变化了, 需要单独处理下, 否则找不到系统文件:
my $xll_path = catfile $lib_root, 'ANALYS32.XLL';
my $xla_path = catfile $lib_root, 'ATPVBAEN.XLAM';
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP