开发者

Perl, ppm, and trying to download module dependencies

开发者 https://www.devze.com 2023-02-05 21:14 出处:网络
I have Strawberry Perl and PPM installed.I am no stranger to installing modules by hand from CPAN, but recently came into one of those situations where a module required one dependency and -that- depe

I have Strawberry Perl and PPM installed. I am no stranger to installing modules by hand from CPAN, but recently came into one of those situations where a module required one dependency and -that- dependency required twenty..

So I decided to give PPM a whirl (because that automatically installs dependencies, right?), and I initially thought it worked like Ruby Gems. I loaded it and typed:

ppm> install OLE::Storage_Lite

from this tutorial.

Then I ra开发者_StackOverflow中文版n into the problem saying 'Could not locate a PPDfile'.

So I followed this tutorial which walks you through hooking up a link to a repository, and it still couldn't find the PPD file.

My question is: Can anyone help me load a Perl module so I can read and write from Excel files!?

Solved: My problem turned out to be a proxy server at work that wouldn't allow me to download packages through PPM.


Two things:

  1. CPAN can install dependencies too! :) just do a cpan install My::Module on the command line to get your module and its dependencies installed.
  2. Use Win32::OLE instead.

Win32::OLE is the standard module for interacting with COM and OLE objects in windows, and it works great. It's already included with Strawberry Perl, and it works well! You just need to look at the documents regarding Perl and 'OLE Automation'. It would look something like this:

use strict;
use warnings;
use Win32::OLE; 
use Win32::OLE::Const 'Microsoft Excel';  # brin in Excel constants

my $excel = Win32::OLE->new('Excel.Application') or die "oops\n";

In fact, if you check out the Win32::OLE docs on CPAN, you'll see that they have several examples right there on how to get Excel automation working.

After that, a quick search for "Excel OLE Automation" will bring up a lot of tutorials showing you all the methods you need to call and quirks of Excel. But after that, it's pretty straight forward! Some examples:

my $sheet = $excel->Worksheets(1);  #Gets the first worksheet, 1 indexed
$sheet->Cells($row, $col); # do something to a cell 
$sheet->Columns("A:D");    # do something to some columns
$sheet->Rows($row_number); # do something to a row

There's obviously a lot more (The excel API is pretty vast) but this should get ya started.

0

精彩评论

暂无评论...
验证码 换一张
取 消