Hi, I'm trying to use Conditional Formatting. I recorded the Macro (comment inside code) and tried to translate to Perl OLE with the code below but got error: Can't call method "Font" on an undefined value at excel_test.pl line 56. I can loop through each cell and check if it not equal to "TRUE" and assign color. I'm trying to avoid looping in Perl.
use strict; use warnings; use Win32::OLE; use Win32::OLE qw(in with); my $EXCEL = Win32::OLE->new("Excel.Application","Quit"); $EXCEL->{"Visible"} = 1; $EXCEL->{DisplayAlerts}= 0; my $outfile = "C:\\test\\file1.xls"; $EXCEL -> {"SheetsInNewWorkBook"} = 1; my $Workbook = $EXCEL -> Workbooks -> Add(); my $CurrentSheet = $Workbook -> Worksheets(1); $CurrentSheet->Range("A1")->{"Value"} = "DataA"; $CurrentSheet->Range("A2")->{"Value"} = "abs"; $CurrentSheet->Range("A3")->{"Value"} = "FALSE"; $CurrentSheet->Range("A4")->{"Value"} = "TRUE"; $CurrentSheet->Range("A5")->{"Value"} = "ABC"; $CurrentSheet->Range("A6")->{"Value"} = "xyz"; $CurrentSheet->Range("A7")->{"Value"} = "123"; $CurrentSheet->Range("A8")->{"Value"} = "-99999"; $CurrentSheet->Range("A9")->{"Value"} = "TRUE"; $CurrentSheet->Range("A10")->{"Value"} = "10"; $CurrentSheet->Range("B1")->{"Value"} = "DataB"; $CurrentSheet->Range("B2")->{"Value"} = "absx"; $CurrentSheet->Range("B3")->{"Value"} = "FALSE"; $CurrentSheet->Range("B4")->{"Value"} = "TRUE"; $CurrentSheet->Range("B5")->{"Value"} = "ABCx"; $CurrentSheet->Range("B6")->{"Value"} = "xyzx"; $CurrentSheet->Range("B7")->{"Value"} = "123x"; $CurrentSheet->Range("B8")->{"Value"} = "-99999x"; $CurrentSheet->Range("B9")->{"Value"} = "TRUE"; $CurrentSheet->Range("B10")->{"Value"} = "10x"; $CurrentSheet->Range("C1")->{"Value"} = "A=B?"; #my $rangeFormat = $CurrentSheet->Range("A4"); #$rangeFormat->Interior->{Color} = 255; # Columns("A:A").Select # Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNot +Equal, _ # Formula1:="=TRUE" # Selection.FormatConditions(Selection.FormatConditions.Count).SetF +irstPriority # With Selection.FormatConditions(1).Font # .Color = -16776961 # .TintAndShade = 0 # End With # Selection.FormatConditions(1).StopIfTrue = True my $rangeFormat = $CurrentSheet->Range("A:A"); $rangeFormat->FormatConditions->Add({Type=>"xlCellValue", Operator=>"x +lNotEqual", Formula1=>"=TRUE"}); $rangeFormat->FormatConditions(1)->Font->{Color} = -16776961; $Workbook->SaveAs({FileName => $outfile, FileFormat => -4143}); $Workbook -> Save(); $EXCEL->Quit(); Win32::OLE->FreeUnusedLibraries();

In reply to Win32::OLE Excel Conditional Formatting error by slick.user

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.