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 5031 miller 1,089
Recognized Expert Top Contributor
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
miller 1,089
Recognized Expert Top Contributor
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::Wr iteExcel
- 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
miller 1,089
Recognized Expert Top Contributor
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.
miller 1,089
Recognized Expert Top Contributor
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 specific ranges
and enter data into cells, but what I'm looking for at this point is
how to set the background color of cells.
Does anybody know how to do this with Win32::OLE? If this module maps
to Microsoft's API, is there any complete...
|
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.
Cygwin
perl 5.8.6-4
Windows XP SP1
|
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: instead of either opening a file or creating a new one, I'd like to do BOTH. I was thinking of creating a loop where I could basically say something like:
if $excelfile exists, then open $excelfile, otherwise, create a new workbook named...
|
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 the INTERFACE argument in it tells the Win32::OLE module the name of the event interface that an application must implement to receive event notifications from a WebBrowser control or from the Microsoft Internet Explorer application.
So My...
|
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 my script executes. Is there any way I can specify the readonly attribute in my code so i dont have to click on read only.
| |
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): GetOleTypeLibObject() Not a Win32::OLE::TypeLib object at C:/Perl/site/lib/Win32/OLE/Const.pm line 45.
Died at D:\Genes_datasets\exp.pl line 6.
i don't ve microsoft excel but open office installed, i think that could be a problem. But these...
|
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 giving the script i used for opening excel file..
So i want to know how to provide password parameter while opening the file.
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Variant qw(:DEFAULT nothing);
|
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 default?
Best Regards,
Adam S
|
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 = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |