I'm running in to some problems in making a OLE application do some stuff in excel (181874)

I was getting unblessed reference errors, though I think I *may* be past that now. Now it says 'Unable to set LineStyle property of the Border class', then it says ERROR exception occurred (hex reference) in PROPERTYPUT "LineSTyle".

Also, the general page itself is not being laid out as I want (the names aren't there--for the worksheets, which themselves aren't all there). Here's the code stripped down.

#!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel::Utility; use Win32::OLE qw(in valof with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::NLS qw(:DEFAULT :LANG :SUBLANG); $Win32::OLE::Warn = 3; my $file = 'test.txt'; open (TABFILE,$file) or die "$file: $!"; # Create a new Excel workbook my $file_name = 'test.xls'; my $xl = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "error message"; my $book = $xl->Workbooks->Add(); my $sheet1 = $xl->Worksheets->Add(); my $sheet2 = $xl->Worksheets->Add(); $sheet1->{Name} = 'all_avg'; $sheet2->{Name} = 'grp_avg'; #$sheet2->Activate(); $book->SaveAs($file_name); my @edges = qw (xlEdgeBottom xlEdgeLeft xlEdgeRight xlEdgeTop xlInsideHorizontal xlInsideVertical); my @ranges = qw (B1 A2:G2 B16 A17:E17 B31 A32:E32 B46 A47:E47); for my $range (@ranges) { for my $edge (@edges) { with (my $Borders = $sheet2->Range($range)->Borders(eval($edge)), LineStyle =>xlContinuous, Weight => xlThin , ColorIndex => 1); } } for my $edge (@edges) { with (my $Borders = $sheet1->Range('A1:G1')->Borders(eval($edge)), LineStyle =>xlContinuous, Weight => xlThin , ColorIndex => 1); } $book->SaveAs($file_name); for (<TABFILE>) { $sheet1->Range(x1_rowcol_to_cell($row,$col))->{Value} = $_; } $book->SaveAs($file_name); $sheet1->Range('A1:G1')->{Value} = @$headers1; for(2,17,32,47) { $sheet2->Range(x1_rowcol_to_cell($_,0))->{Value} = @cats } for(0,15,30,45) { $sheet2->Range(x1_rowcol_to_cell($_,1))->{Value} = @$headers3; } for(1,16,31,46) { $sheet2->Range(x1_rowcol_to_cell($_,0))->{Value} = @$headers2; } $sheet2->Range(x1_rowcol_to_cell(1,5))->{Value} = ('Rest EMG', 'IMC EMG'); ## inside several for loops $sheet2->Range($cells->[$gr][$avg][$cond])->{Value} = $form; $book->SaveAs($file_name);

In reply to Win32::OLE Woes by dimmesdale

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.