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

Home Posts Topics Members FAQ

Perl - Win32::OLE - Excel Formulas

11 New Member
I am a Perl Programmer & i am using WIN32::OLE for Excel operations.

I wanted to use conditional formulas like 'if' in excel via Perl.

Thanks in Advance.
Mar 31 '11
13 4690
miller
1,089 Recognized Expert Top Contributor
You don't need that incremental translation using chr and ord. Instead just rely on your original variable.

Expand|Select|Wrap|Line Numbers
  1. my $column = 'A';
  2.  
  3. for my $i (1..100) {
  4.     print "$column ";
  5.     $column++;
  6. }
  7.  
Outputs

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ
AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ BA BB BC BD BE BF BG BH BI BJ
BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK
CL CM CN CO CP CQ CR CS CT CU CV
Apr 4 '11 #11
miller
1,089 Recognized Expert Top Contributor
Note, an even cleaner way of doing it is to use the .. operator.

Expand|Select|Wrap|Line Numbers
  1. for my $column ('A'..'CV') {
  2.     print "$column ";
  3. }
  4.  
Apr 4 '11 #12
miller
1,089 Recognized Expert Top Contributor
It's also good to know a functional way to translate a column number into excel notation. Here's one way to do that

Expand|Select|Wrap|Line Numbers
  1. sub excel_col {
  2.     my $val = shift;
  3.  
  4.     my $str = '';
  5.  
  6.     do {
  7.         $val-- if $str ne '';
  8.         my $r = $val % 26;
  9.         $val = ($val - $r) / 26;
  10.         $str = chr(ord('A') + $r) . $str;
  11.     } while ($val > 0);
  12.  
  13.     return $str;
  14. }
  15.  
  16. for my $i (0..1000) {
  17.     print excel_col($i) . ' ';
  18. }
  19.  
Apr 4 '11 #13
Prasanna CRN
11 New Member
Thanks Miller. I had used alternative way as per my use case.(with some limitations)
But yours will be applied in broader manner.
Apr 5 '11 #14

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
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
5032
by: dilipkvarma | last post by:
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;
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
9481
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
10336
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...
0
10155
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8978
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
7502
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
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.