Here's a Batch/Perl polyglot that reads the first sheet of a spreadsheet, expands the data, and writes it to the fourth sheet:
@rem = '--*-Perl-*-- @echo off if exist C:\Perl\bin\perl.exe goto ok if exist D:\Perl\bin\perl.exe goto ok if exist E:\Perl\bin\perl.exe goto ok echo Perl not properly installed goto endofperl :ok perl "%~dpnx0" %* goto endofperl @rem '; #!perl #line 14 # use strict; # use warnings; use Win32::OLE; # use existing instance if Excel is already running eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $ex) { $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; } my $file = shift; my $book = $ex->Workbooks->Open($file) or die "Can't open $file"; my $source = $book->Worksheets(1) or die "Can't access first sheet"; my $target = $book->Worksheets(4) or die "Can't access fourth sheet"; my $startrow = 3; my $stoprow = 199; my $array = $source->Range("A$startrow:Q$stoprow")->{Value}; my $writerow = $startrow; for (@$array) { my @vals = (); for (@$_) { push @vals,$_ } next unless defined($vals[0]); my @bitlist = (); for (my $pos = 0; $pos < scalar @vals; ++$pos) { push @bitlist,$pos if $vals[$pos] eq '>=0'; } my $max_val = 2 ** (scalar @bitlist); for my $val ( 0..$max_val-1 ) { my @newvals = @vals; for my $bit (@bitlist) { $newvals[$bit] = ($val/2 == $val>>1) ? 1 : 0; $val >>= 1; } for ( @newvals ) { s/>0/1/; # >0 becomes 1 s/'?([0-9]+)/'$1/; # Make sure ' is present for numbers } $target->Range("A$writerow:Q$writerow")->{Value} = [@newvals]; for (@newvals) { s/^'//; } my @single = ($newvals[3].$newvals[4].$newvals[5].$newvals[6]. $newvals[7].$newvals[8].$newvals[9].$newvals[10]. $newvals[11].$newvals[12].$newvals[13].$newvals[14]) +; $target->Range("C$writerow:C$writerow")->{Value} = [@single]; ++$writerow; print join("\t",@newvals)."\n"; } } # save and exit $book->Save(); $book->Close(); undef $book; undef $ex; __END__ :endofperl

In reply to Re: Can I Create/Access an excel file ? by PhilHibbs
in thread Can I Create/Access an excel file ? by subbu

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.