473,785 Members | 2,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Win32::OLE Excel - Running Subtotal command

8 New Member
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

Expand|Select|Wrap|Line Numbers
  1. $Sheet->Activate;
  2. $Range = $Sheet->Range("A2:C$Row");
  3. $Range->Select;
  4.  
  5. @TotalList = (2, 3);
  6. $Excel->Selection->Subtotal({GroupBy => 1, Function => xlCount, TotalList => (2)});
  7.  
Any help on this is highly appreciated

Thanks in advance
Dilip
Jul 17 '07 #1
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
Jul 17 '07 #2
dilipkvarma
8 New Member
Hi Miller,

Thank you for pointing out my mistake, I accept that and my sincere apologies.

Please find below the compilable code:

Expand|Select|Wrap|Line Numbers
  1. use Win32::OLE;
  2.  
  3. #############################################
  4. # Create Excel instance
  5. #############################################
  6. # Start Excel and make it visible
  7. $Excel = Win32::OLE->new('Excel.Application');
  8. $Excel->{SheetsInNewWorkbook} = 1;
  9. $Excel->{Visible} = 1;
  10.  
  11. #############################################
  12. # Add sheet
  13. #############################################
  14. my $Book = $Excel->Workbooks->Add;
  15. my $Sheet = $Book->Worksheets(1);
  16. $Sheet->{Name} = 'Sample';
  17.  
  18. # Insert column titles
  19. my $Range = $Sheet->Range("A1:C1");
  20. $Range->{Value} = ["One","Two", "Three"];
  21. $Range->Font->{Bold} = 1;
  22.  
  23.  
  24. #############################################
  25. # Generate some sample data
  26. #############################################
  27. for ($Row=2; $Row<6; $Row++) {
  28.     $Range = $Sheet->Range("A$Row:C$Row");
  29.     $Range->{1} = $Row;
  30.     $Range->{2} = $Row;
  31.     $Range->{3} = $Row;
  32. }
  33.  
  34. for (; $Row<25; $Row++) {
  35.     $Range = $Sheet->Range("A$Row:C$Row");
  36.     $Range->{1} = $Row;
  37.     $Range->{2} = $Row;
  38.     $Range->{3} = $Row;
  39. }
  40.  
  41. for ($R=2; $R<13; $R++) {
  42.     $Range = $Sheet->Range("A$Row:C$Row");
  43.     $Range->{1} = $R;
  44.     $Range->{2} = $R;
  45.     $Range->{3} = $R;
  46.     $Row ++;
  47. }
  48.  
  49. $Range = $Sheet->Range("A2:C$Row");
  50. $Range->Sort($Range->Range("A2"));
  51.  
  52. $Sheet->Activate;
  53. $Range = $Sheet->Range("A1:C$Row");
  54. $Range->Select;
  55.  
  56. @TotalList = (2, 3);
  57. $Excel->Selection->Subtotal({GroupBy => 1, Function => xlCount, TotalList => \@TotalList});
  58.  
  59. __END__
  60.  
Thanks & regards
Dilip
Jul 18 '07 #3
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
Jul 18 '07 #4
dilipkvarma
8 New Member
Thank you for quick reply, but my site does not have that package installed and I do not have permissions to install it.

Dilip
Jul 18 '07 #5
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
Jul 18 '07 #6
dilipkvarma
8 New Member
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.
Jul 19 '07 #7
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
Jul 19 '07 #8
dilipkvarma
8 New Member
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
Jul 20 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
13106
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...
2
6180
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
3
41794
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...
2
2992
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...
2
4438
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.
8
36592
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...
1
6209
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);
1
1626
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
6
6482
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) {
1
4521
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';
0
9645
marktang
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...
0
9480
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,...
0
10330
Oralloy
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...
1
10093
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,...
0
8976
agi2029
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...
1
7500
isladogs
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...
0
5381
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...
1
4053
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
3
2880
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.