in reply to Conditional Formating with OLE Excel
When Excel uses the word "Format", it can have at least two meanings. The commonest meaning is more strictly defined as "NumberFormat", i.e. whether a number appears as "1" or "1.00". You seem to be looking for the other meaning, but you may need to be aware of the difference, as the NumberFormat cannot be set by conditional formatting.
Second, there is a lot of history to conditional formatting that your code needs to respect. Conditional formatting came in with Excel 97 (I think), so in the unlikely event that you have such old versions lying around your user base, they will throw errors. 2007 increased the number of conditions permitted from 3 to (I think) unlimited, so if you try to process a file written in 2007/2010 with 2003, conditions will be dropped and the appearance may not be what you expect. However, getting around this limit in 1997-2003 is a FAQ, with this showing the answer.
Third, conditional formatting behaves strangely. See John Walkenbach's issues, especially his comment that "There is no direct way for your VBA code to determine if a particular cell's conditional formatting has been "triggered."". This means that there is no way for Perl to do it, unless you want to write a parser.
If you do want to write a parser, you're a braver man than I am. Bear in mind that you won't know the number of conditions, so you should start looking at $rng->FormatConditions->Count. You will then have to parse each condition, bearing in mind that the operators will not be returned as operators but as integers. You will have to research all versions of Excel you are going to meet to be sure that you can handle all possible options. I would guess that, in writing your own Perl parser, you would obviate the need for the R1C1 conversion, but that is something that you would have to test.
It's possible that your case will be sufficiently restricted that you can write a parser. The code you show looks only at the pattern, so perhaps you aren't interested in anything else, but even so, parsing the conditions is going to be a pig. You might consider going back to the OzGrid reference I gave earlier and replacing conditional formatting with some VBA that changes the primary format rather than using conditional formatting.
Your code starts by taking control of an assumed existing instance of Excel. See Re: Manipulating open excel sheet for some reasons not to do this.
Good luck. I think you're going to need it.
Regards,
John Davies
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Conditional Formating with OLE Excel
by fredo2906 (Acolyte) on Oct 13, 2011 at 05:19 UTC | |
by davies (Monsignor) on Oct 13, 2011 at 11:11 UTC |