How to extract images from Excel files with OLE?

Perl No Comments »

#!/usr/bin/perl

use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...

my $filename = 'C:\ist\Win32\OLE\ChartOLE\chart.xls';
my $filter = 'GIF'; # can be GIF, JPG, JPEG or PNG
my $count = 0;

my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit'); # use the Excel application if it's open, otherwise open new
my $Book = $Excel->Workbooks->Open( $filename ); # open the file
foreach my $Sheet (in $Book->Sheets) { # loop through all sheets
foreach my $ChartObj (in $Sheet->ChartObjects) { # loop through all chartobjects in the sheet
my $savename = "$filename." . $count++ . ".$filter";
$ChartObj->Chart->Export({
FileName => $savename,
FilterName => $filter,
Interactive => 0});
}
}
$Book->Close;

Handling Microsoft Word and Excel files using OLE

Perl No Comments »

This perl code running under Windows 32 operating systems, and requires the MS Office to be installed.
#!/usr/bin/perl

use Win32::OLE::Const 'Microsoft Excel';
printf "xlMarkerStyleDot = %d\n", xlMarkerStyleDot;
my $wd = Win32::OLE::Const->Load("Microsoft Word 9\\.0 Object Library");
foreach my $key (keys %$wd) {
printf "$key = %s\n", $wd->{$key};
}

How to extract HREF links from the input

Perl No Comments »

#!/usr/bin/perl -n00
print "$2\n" while m{
< \s*
A \s+ HREF \s* = \s* (["']) (.*?) \1
\s* >
}gsix;

Searching in the source of a webpage

Perl No Comments »

#!/usr/bin/perl
use LWP::Simple;
$count = 0;
$search = $#ARGV >= 0 ? $ARGV[1] : "author";
$server = $#ARGV >= 1 ? $ARGV[0] : "www.webhauser.com";

$page = get "http://$server";
@lines = split /[\n\r]+/, $page;
foreach $line (@lines) {
if ( $line =~ /$search/ ) {
print "found: $line\n";
$count++;
}
}

print '-'x70 ."\n";
print "internet szerver: $server\n";
print "keresett szo: $search\n";
print "Talalat $count sorban\n";

Getting the source of a webpage

Perl No Comments »

#!/usr/bin/perl

use LWP::Simple;

print $ARGV[0];
print "\n";
getprint "http://" . $ARGV[0];

How to use a here-document to assign an array

Perl No Comments »

To use a here-document to assign an array, one line per element, you might use an approach like this:

@sauces = <<End_lines =~ m/(\S.*\S)/g;
	normal tomato
	spicy tomato
	green chile
	pesto
	white wine
End_Lines

Read file at once enable localized slurp mode

Perl No Comments »


open my $fh, "foo" or die $!;
local $/;
my $content = <$fh>;
close $fh;

Assign to our array, an array of array references

Perl No Comments »

@AoA = (
           [ "fred", "barney" ],
           [ "george", "jane", "elroy" ],
           [ "homer", "marge", "bart" ],
);

print $AoA[2][2];	#      bart

Split string into array

Perl No Comments »


$x = "Calvin and Hobbes";
@words = split /\s+/, $x;

Using arrays

Perl No Comments »

@words = ($x =~ /(\w+)/g);

WebSite Powered by webHauser
Entries RSS Comments RSS Login