XLS

#!/usr/bin/perl -w
#function:            select records from table and print to Excel file
#author:              ATGC
#version:             1.0
#date of compilation  September 6,2004

use strict;
use Win32::OLE;
my $excel_file = 'output.xls';
my($dbh,$sth,$row,$col,@field,$ele,$c_times,$residual,$cols,$cell_end);
unlink $excel_file if (-e $excel_file);
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $Book = $Excel->Workbooks->add;
my $Sheet = $Book->Worksheets(1);
my @array_cols=("","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$row=1;
$cols=0;
if (@field = $sth->fetchrow)
{
 $cols=scalar(@field);
 $c_times=int($cols/26);
 $residual=$cols%26;
 if ($cols<27)
 {
  $cell_end = $array_cols[$cols];
 }
 else
 {
  if ($residual == 0)
  {
   $cell_end = $array_cols[$c_times-1]."Z";
  }
  else
  {
   $cell_end = $array_cols[$c_times].$array_cols[$residual];
  }
 }
 $Sheet->Range("A1:$cell_end$row")->{Value} = [@field];
 while(@field = $sth->fetchrow)
 {
  $row++;
  $Sheet->Range("A$row:$cell_end$row")->{Value} = [@field];
 }
 $Book->SaveAs($excel_file);
}
undef($Sheet);
undef($Book);
undef($Excel); 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值