将一个Array对象与标量中的标量值组合在一起? Perl的

时间:2015-03-30 15:46:21

标签: perl

我正在尝试将数组列表中的项与标量$range组合在一起。这是我试图这样做的方式。

my $rowinc = 2;
my $colarray = @collet[0];
my $range = $colarray $rowinc;
chomp $range;


$sheet->Range($range)->{Value} = $ir;
    shift @collet;
$sheet->Range($range)->{Value} = $sn;
    shift @collet;
$sheet->Range($range)->{Value} = (join(", ", @parts));
    shift @collet;
$sheet->Range($range)->{Value} = $ref;
    $rowinc++;
    unshift @collet, 'C';
    unshift @collet, 'B';
    unshift @collet, 'A';

我尝试了多种方法,但无济于事。这是我在运行此特定代码段时收到的错误。

Scalar found where operator expected at gen1.pl line 87, near "$colarray $rowinc
"
        (Missing operator before $rowinc?)
syntax error at gen1.pl line 87, near "$colarray $rowinc"
Execution of gen1.pl aborted due to compilation errors.
Press any key to continue . . .

我假设数组不能以这种方式用来表示$ range的值。我遇到的问题是我使用Win32 :: OLE来管理我的Excel电子表格,因为它使我能够打开已有的电子表格。但缺点是我无法输入我的单元格区域作为整数($ row,$ col)我试过这只是递增$row$col我希望能够有效地管理它而不是使用一堆if if和什么不是。

我试图做的是@collet = ('A', 'B', 'C', 'D'); 告诉我要打印哪一列,如果我从0开始它应该开始在A col中打印。这是好的,然后每次在列中打印它向右移动,所以现在@collet[0]应该是'B'。我知道这不是最好的方法,但我已经改变了原来的方法,希望能解决这个问题。任何帮助都会很棒!

这是我的完整脚本。

#!C:\Perl\bin
#manage IR/SRN/Parts Used
#Written for Zebra
#Author Dalton Brady
#Location Bentonville AR

use strict;
use warnings;
use POSIX qw(strftime);
use Win32::OLE;
use Win32::OLE qw( in with);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Variant;


$Win32::OLE::Warn = 3;    #Die on errors

#different types of units worked on, trying to name the worksheet 
#after one depending on user input have yet to add that func.
my @uut = ('VC5090', 'MK2046', 'MK2250', 'MK4900', '@pos');

my $ref = strftime '%Y-%m-%d', localtime(); #create the datestamp
my $i   = 0;                         #increment counter for why loop
my $n   = 0;                         #increment for do until loop
my $xfile = 'X:\dataTest\data.xls';  #location of excel file
my $book;     #place for the workbook to exist
my $sheet;    #worksheet exists here
my $ex;       #a place to hold the excel application
my $row = 2;  #track row in which data will 
              #be placed with the do until loop 
my $col = 1;
my @parts ; # store the different parts as a list within 
            # an area (to be written to the spreadsheet)
my @talk = ( 'IR:', 'SN:', 
             '#of Parts Used: ', 'PN:', 
             'Units Completed: ');
my @collet = "A" .. "Z"


# start an instance of excel

$ex = Win32::OLE->new('Excel.Application');
$ex->{DisplayAlerts} = 0;    #turn off alerts/textboxes/saveboxes

#check to see if excel file exists if yet open it, if not create it
if (-e $xfile) {
  $book  = $ex->Workbooks->Open($xfile);
  $sheet = $book->Worksheets("Test");
  $sheet->Activate();
}
else {
  $book = $ex->Workbooks->Add()
    ;    #create new workbook to be used because we couldn't find one
  #########SETUP YOUR EXCEL FILE#############
  $sheet = $book->Worksheets("Sheet1");
  $sheet->Activate();
  $sheet->{Name}                             = "Test";
  $sheet->Cells("a1")->{HorizontalAlignment} = x1HAlignCenter;
  $sheet->Cells("b1")->{HorizontalAlignment} = x1HAlignCenter;
  $sheet->Cells("c1")->{HorizontalAlignment} = x1HAlignCenter;
  $sheet->Columns("a")->{ColumnWidth}        = 20;
  $sheet->Columns("b")->{ColumnWidth}        = 20;
  $sheet->Columns("c")->{ColumnWidth}        = 30;
  $sheet->Range("a1")->{Value}               = "IR Number";
  $sheet->Range("b1")->{Value}               = "Serial Number";
  $sheet->Range("c1")->{Value}               = "Parts Used";
  $sheet->Range("d1")->{Value}               = "Date";

  $book->SaveAs($xfile);    #Save the file we just created
}

# ask for how many units user will be 
# scanning or has completed to be scanned
print $talk[4] ; 

#unit count tracker, determines how many times the do while loop runs
my $uc = <>; 
do {

  print $talk[0];    #ask for the IR number
  my $ir = <>;
  chomp $ir;
  print $talk[1];    #ask for uut Serial Number
  my $sn = <>;
  chomp $sn;
  print $talk[2];

# ask for the number of parts used, to regulate 
# the parts list storage into the @parts array
  my $pu = <>;

  while ($i < $pu) {

    print $talk[3];
    my $scan = <>;
    chomp $scan;
    push @parts, $scan;
    $i++;
  }

  my $rowinc   = 2;
  my $colarray = @collet[0];
  my $range    = $colarray $rowinc;
  chomp $range;


  $sheet->Range($range)->{Value} = $ir;
  shift @collet;
  $sheet->Range($range)->{Value} = $sn;
  shift @collet;
  $sheet->Range($range)->{Value} = (join(", ", @parts));
  shift @collet;
  $sheet->Range($range)->{Value} = $ref;
  $rowinc++;
  unshift @collet, 'C';
  unshift @collet, 'B';
  unshift @collet, 'A';


} until ($n == $uc);


# save and exit
$book->SaveAs($xfile);
$book = $ex->WorkBooks->Close();
undef $book;
undef $ex;

0 个答案:

没有答案