Skip to main content

ConditionalFormatFormula

Struct ConditionalFormatFormula 

Source
pub struct ConditionalFormatFormula { /* private fields */ }
Expand description

The ConditionalFormatFormula struct represents a Formula style conditional format.

ConditionalFormatFormula is used to represent a Formula style conditional format in Excel. A Formula conditional format highlights formula values in a range based on a user supplied formula.

For more information see Working with Conditional Formats.

§Examples

Example of adding a Formula type conditional formatting to a worksheet. Cells with odd numbered values are in light red while even numbered values are in light green.

    // Write a conditional format over a range.
    let conditional_format = ConditionalFormatFormula::new()
        .set_rule("=ISODD(B3)")
        .set_format(format1);

    worksheet.add_conditional_format(2, 1, 11, 10, &conditional_format)?;

    // Write another conditional format over the same range.
    let conditional_format = ConditionalFormatFormula::new()
        .set_rule("=ISEVEN(B3)")
        .set_format(format2);

    worksheet.add_conditional_format(2, 1, 11, 10, &conditional_format)?;

This creates conditional format rules like this:

And the following output file:

Implementations§

Source§

impl ConditionalFormatFormula

Source

pub fn new() -> ConditionalFormatFormula

Create a new Formula conditional format struct.

Source

pub fn set_rule(self, rule: impl Into<Formula>) -> ConditionalFormatFormula

Set the rule of a Formula conditional format.

Set the formula rule in a Formula style conditional format.

There are some caveats to be aware of when creating the formula:

  • The formula must evaluate to a boolean, number, date, time or string.
  • Some newer “dynamic range” style functions aren’t supported by Excel in Formula conditional formats.
  • The formula should be in English with US style punctuation. See Formula for details.

If you encounter any issues you should verify that the formula works in Excel before transferring it to rust_xlsxwriter.

§Parameters
  • value: A Formula value or type that converts “into” a Formula such as a &str or &Formula.
§Examples

Example of adding a Formula type conditional formatting to a worksheet. Cells with odd numbered values are in light red while even numbered values are in light green.

    // Write a conditional format over a range.
    let conditional_format = ConditionalFormatFormula::new()
        .set_rule("=ISODD(B3)")
        .set_format(format1);

    worksheet.add_conditional_format(2, 1, 11, 10, &conditional_format)?;

    // Write another conditional format over the same range.
    let conditional_format = ConditionalFormatFormula::new()
        .set_rule("=ISEVEN(B3)")
        .set_format(format2);

    worksheet.add_conditional_format(2, 1, 11, 10, &conditional_format)?;

Output file:

Source

pub fn set_format(self, format: impl Into<Format>) -> ConditionalFormatFormula

Set the Format of the conditional format rule.

Set the Format that will be applied to the cell range if the conditional format rule applies. Not all cell format properties can be set in a conditional format. See Excel’s limitations on conditional format properties for more information.

See the examples above.

§Parameters
  • format: The Format property for the conditional format.
Source§

impl ConditionalFormatFormula

Source

pub fn set_multi_range( self, range: impl Into<String>, ) -> ConditionalFormatFormula

Set an additional multi-cell range for the conditional format.

The set_multi_range() method is used to extend a conditional format over non-contiguous ranges like "B3:D6 I3:K6 B9:D12 I9:K12".

See Selecting a non-contiguous range for more information.

§Parameters
  • range: A string like type representing an Excel range.

    Note, you can use an Excel range like "$B$3:$D$6,$I$3:$K$6" or omit the $ anchors and replace the commas with spaces to have a clearer range like "B3:D6 I3:K6". The documentation and examples use the latter format for clarity but it you are copying and pasting from Excel you can use the first format.

    Note, if the range is invalid then Excel will omit it silently.

Source

pub fn set_stop_if_true(self, enable: bool) -> ConditionalFormatFormula

Set the “Stop if True” option for the conditional format rule.

The set_stop_if_true() method can be used to set the “Stop if true” feature of a conditional formatting rule when more than one rule is applied to a cell or a range of cells. When this parameter is set then subsequent rules are not evaluated if the current rule is true.

§Parameters
  • enable: Turn the property on/off. It is off by default.

Trait Implementations§

Source§

impl Clone for ConditionalFormatFormula

Source§

fn clone(&self) -> ConditionalFormatFormula

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConditionalFormat for ConditionalFormatFormula

Source§

fn validate(&self) -> Result<(), XlsxError>

Validate the conditional format. Read more
Source§

fn rule( &self, dxf_index: Option<u32>, priority: u32, range: &str, guid: &str, ) -> String

Return the conditional format rule as an XML string.
Source§

fn x14_rule(&self, priority: u32, guid: &str) -> String

Return the extended x14 conditional format rule as an XML string.
Source§

fn format_as_mut(&mut self) -> Option<&mut Format>

Get a mutable reference to the format object in the conditional format.
Source§

fn format_index(&self) -> Option<u32>

Get the index of the format object in the conditional format.
Source§

fn multi_range(&self) -> String

Get the multi-cell range for the conditional format, if present.
Source§

fn has_x14_extensions(&self) -> bool

Check if the conditional format uses Excel 2010+ extensions.
Source§

fn has_x14_only(&self) -> bool

Check if the conditional format uses Excel 2010+ extensions only.
Source§

fn box_clone(&self) -> Box<dyn ConditionalFormat + Sync + Send>

Clone a reference into a concrete Box type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V