I'm trying to change some code I have using SpreadSheet::WriteExcel to Win32::OLE compatible. Well, I don't know where to begin (well, actually, I've begun, just not much). I've got a script using WriteExcel, but when mixing it with OLE, I was getting some wierd things, so I'm going to change it all to OLE. My code is thus:

# All non-excel stuff taken out for your viewing ease ;) #!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; use Spreadsheet::WriteExcel::Utility; ... my $file = 'test.txt'; open (TABFILE,$file) or die "$file: $!"; # Create a new Excel workbook my $workbook = Spreadsheet::WriteExcel->new('TEST2.xls'); my $worksheet = $workbook->addworksheet('all_avg'); my $group_avg = $workbook->addworksheet('gr_avg'); my $h_frmt = $workbook->addformat( border => 2, fg_color => 'silver', pattern => 1); my $headers1 = [ 'TS# and Condition', 'Rest HRT', 'IMC HRT', 'Rest SKT', 'IMC SKT', 'Rest EMG', 'IMC EMG' ]; my $headers2 = [ 'Condition', 'Rest HRT', 'IMC HRT', 'Rest SKT', 'IMC SKT' ]; my $row = 1; my ($cells,$formula,$ts2); for (<TABFILE>) { ... my $col = 0; for (@vals) { ... $worksheet->write($row, $col, $_); $col++; } $row++; } $worksheet->write(0,0, $headers1, $h_frmt); for(2,17,32,47) { $group_avg->write_col($_,0, \@cats) } $group_avg->write(0,1, 'Low-Hour VFR',$h_frmt); $group_avg->write(15,1, 'Low-Hour Instruments',$h_frmt); $group_avg->write(30,1, 'High-Hour Instruments',$h_frmt); $group_avg->write(45,1, 'All Groups',$h_frmt); $group_avg->write_row(1,5, ['Rest EMG', 'IMC EMG'], $h_frmt); for(1,16,31,46) { $group_avg->write_row($_,0, $headers2, $h_frmt) } for my $gr (0..3) { for my $avg(0..5) { for my $cond(0..$#cats) { my $ts = shift @{$ts2->[$gr][$avg][$cond]}; if( ($avg < 4) || ($gr == 0 && $ts >= 21) ) { my $sheet = $worksheet->get_name(); my $form = "=AVERAGE(${sheet}!" . join(",${sheet}!", @{$formula->[$gr][$avg][$cond]}) . ')'; $group_avg->write_formula( $cells->[$gr][$avg][$cond], $form ) +; } } } }

The massive amount I could figure from the (in my view sketchy) documentation is this:

my $file_name = 'test.xls'; my $xl = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit; +}) or die "Excel failed to load: Win32::OLE->new"; my $book = $xl->Workbooks->Add(); my @sheets = $xl->Worksheets(2); $sheets[0]->{Name} = 'all_avg'; $sheets[1]->{Name} = 'grp_avg'; $book->SaveAs($file_name)

I saw some things (e.g., Workbooks->Add()) on some nodes here, and an article in the perl journal, but the documentation never mentioned anything about these methods. Where can I find a list of them (preferably with some explanation/mention of calling convention)


In reply to WriteExcel to OLE? 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.