Hi All,
I am trying to create a subtotal in an Excel sheet through Perl script. Some how I am not able to make it work.
Here is what I wrote -
$Sheet->Activate;
-
$Range = $Sheet->Range("A2:C$Row");
-
$Range->Select;
-
-
@TotalList = (2, 3);
-
$Excel->Selection->Subtotal({GroupBy => 1, Function => xlCount, TotalList => (2)});
-
Any help on this is highly appreciated
Thanks in advance
Dilip
8 5012
Whenever you post code, attempt to make it compilable by the expert reading it. In this instance, you have not stated what perl module you using (Where's your use Module statement?), and you've also not shown how you're creating the $Sheet variable. Yes, some of us might be familiar enough with parsing excel spreadsheets to guess. But don't make us guess.
- Miller
Hi Miller,
Thank you for pointing out my mistake, I accept that and my sincere apologies.
Please find below the compilable code: -
use Win32::OLE;
-
-
#############################################
-
# Create Excel instance
-
#############################################
-
# Start Excel and make it visible
-
$Excel = Win32::OLE->new('Excel.Application');
-
$Excel->{SheetsInNewWorkbook} = 1;
-
$Excel->{Visible} = 1;
-
-
#############################################
-
# Add sheet
-
#############################################
-
my $Book = $Excel->Workbooks->Add;
-
my $Sheet = $Book->Worksheets(1);
-
$Sheet->{Name} = 'Sample';
-
-
# Insert column titles
-
my $Range = $Sheet->Range("A1:C1");
-
$Range->{Value} = ["One","Two", "Three"];
-
$Range->Font->{Bold} = 1;
-
-
-
#############################################
-
# Generate some sample data
-
#############################################
-
for ($Row=2; $Row<6; $Row++) {
-
$Range = $Sheet->Range("A$Row:C$Row");
-
$Range->{1} = $Row;
-
$Range->{2} = $Row;
-
$Range->{3} = $Row;
-
}
-
-
for (; $Row<25; $Row++) {
-
$Range = $Sheet->Range("A$Row:C$Row");
-
$Range->{1} = $Row;
-
$Range->{2} = $Row;
-
$Range->{3} = $Row;
-
}
-
-
for ($R=2; $R<13; $R++) {
-
$Range = $Sheet->Range("A$Row:C$Row");
-
$Range->{1} = $R;
-
$Range->{2} = $R;
-
$Range->{3} = $R;
-
$Row ++;
-
}
-
-
$Range = $Sheet->Range("A2:C$Row");
-
$Range->Sort($Range->Range("A2"));
-
-
$Sheet->Activate;
-
$Range = $Sheet->Range("A1:C$Row");
-
$Range->Select;
-
-
@TotalList = (2, 3);
-
$Excel->Selection->Subtotal({GroupBy => 1, Function => xlCount, TotalList => \@TotalList});
-
-
__END__
-
Thanks & regards
Dilip
Unfortunately, you have surpassed my knowledge with regard to this specific knowledge. I very much prefer the other major package for creating excel files. cpan Spreadsheet::WriteExcel
- Miller
Thank you for quick reply, but my site does not have that package installed and I do not have permissions to install it.
Dilip
Well, here's a question for you. Normally, whenever I want to know about a module's functionality, I simply go straight to cpan: cpan Win32::OLE
In this instance though, that is not all that illuminating. The problem is that in order to document the accepted functionality, it seems like they might have to document all the functionality of Excel itself. I can't imagine that is something that they would choose to do.
So my question to you is, where do you learn how to use this module? All the books about it are very much outdated. The Randal Schwartz book is back from 1997.
- Miller
It is an interesting question. In fact, i am relatively new to PERL and did not have any formal training on PERL. But I am reasonably good in Visual Basic and I used to do these using VBA. And my current assignment requires me to do the above mentioned manipulation using PERL. To get this done, I managed to find some sample PERL scripts that manipulates Excel data. And from there onwards, I was just trying to convert the VBA code into PERL. Since the above code did not throw any compilation or run-time errors, I concluded that the OLE module does support that function, but probably there is something wrong in the invocation.
Once again, thank you very much for your efforts towards this.
Ahh. Well, if you have experience with VisualBasic, then you should be ahead of the curve in knowing how to use this functionality. Unfortunately, to be able to help you with the perl aspect of the problem, it takes more knowledge than I have of the VB side.
If you're looking for a quick introduction to perl, this resource is pretty good: Beginning Perl
And as always, knowing perldoc is very important. http://perldoc.perl.org/
- Miller
No worries Miller.
Thanks for the links (Beginning Perl) and thank you very much for your time and efforts.
Catch you later with some other PERL query
Dilip
Sign in to post your reply or Sign up for a free account.
Similar topics
by: M. David Allen |
last post by:
Hello,
I've been using ActiveState's ActivePerl to generate Excel
spreadsheets using the Win32::OLE module. The rudimentary examples
that are out there on the web show the way to set up...
|
by: usenet |
last post by:
Problem installing Win32::OLE under Cygwin.
I have searched the web and found little documentation on installation
procedure. Please help.
I'd like to get Win32::OLE working under cygwin.
...
|
by: sandycat05 |
last post by:
Hello all, I am a new Perl programmer. Below is the beginnings of a code that I am using to manipulate an Excel spreadsheet via Perl using win32::OLE. However, what I'd like to do is the following:...
|
by: medak |
last post by:
Hi,
I am trying to automate internet explorer using Active Perl’s Win32::OLE Module
I know that WithEvents(OBJECT]method enables and disables the firing of events by the specified OBJECT.
And...
|
by: momukhtar |
last post by:
I am using Win32::OLE to write a perl script which opens an excel file. That excel file is password protected and everytime i run that script dialog box pops up and I have to click on Read-Only then...
|
by: rssd |
last post by:
can somebody help me. I'm trying to read some excel files but i'm always getting this error
No type library matching "Microsoft Excel" found at D:\Genes_datasets\exp.pl line 4
Win32::OLE(0.16):...
|
by: mohanprasadgutta |
last post by:
Hi,
I need help to open a password protected excel file in perl using Win32:OLE.
when I tried to open file in normal way at the time of program execution it is prompting me to enter password.
I am...
|
by: Tension |
last post by:
Hi,
I have written a development automation tool that needs to be distributed to 20-odd developers using Windows XP workstations.
Is there a free Perl distribution that includes "Win32::OLE" by...
|
by: poolboi |
last post by:
hi all,
i've got the following program that needs yr help:
use Win32::OLE;
# use existing instance if Excel is already running
eval {$ex =...
|
by: user1357 |
last post by:
Hi all,
i am trying to run the following code
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |