1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//!
//! Information functions.
//!

pub use crate::generated::info::*;

use crate::{Any, Criterion, FnNumberVar, Reference};
use std::fmt::Write;

/// Parameter for CELL()
#[derive(Debug)]
pub enum CellInfo {
    Address,
    Col,
    Colored,
    Contents,
    Filename,
    Format,
    Formula,
    Parentheses,
    Prefix,
    Protect,
    Row,
    Sheet,
    Type,
    Width,
}

impl Any for CellInfo {
    fn formula(&self, buf: &mut String) {
        let _ = write!(
            buf,
            "{}",
            match self {
                CellInfo::Address => "ADDRESS",
                CellInfo::Col => "COL",
                CellInfo::Colored => "COLORED",
                CellInfo::Contents => "CONTENTS",
                CellInfo::Filename => "FILENAME",
                CellInfo::Format => "FORMAT",
                CellInfo::Formula => "FORMULA",
                CellInfo::Parentheses => "PARENTHESES",
                CellInfo::Prefix => "PREFIX",
                CellInfo::Protect => "PROTECT",
                CellInfo::Row => "ROW",
                CellInfo::Sheet => "SHEET",
                CellInfo::Type => "TYPE",
                CellInfo::Width => "WIDTH",
            }
        );
    }
}

/// Parameter for INFO()
#[derive(Debug)]
pub enum InfoInfo {
    Directory,
    MemAvail,
    MemUsed,
    NumFile,
    OSVersion,
    Origin,
    ReCalc,
    Release,
    System,
    TotMem,
}

impl Any for InfoInfo {
    fn formula(&self, buf: &mut String) {
        let _ = write!(
            buf,
            "{}",
            match self {
                InfoInfo::Directory => "directory",
                InfoInfo::MemAvail => "memavail",
                InfoInfo::MemUsed => "memused",
                InfoInfo::NumFile => "numfile",
                InfoInfo::OSVersion => "osversion",
                InfoInfo::Origin => "origin",
                InfoInfo::ReCalc => "recalc",
                InfoInfo::Release => "release",
                InfoInfo::System => "system",
                InfoInfo::TotMem => "totmem",
            }
        );
    }
}

/// Count the number of cells that meet multiple criteria in multiple ranges.
#[inline]
pub fn countifs<R: Reference + 'static, C: Criterion + 'static, const N: usize>(
    list: [(R, C); N],
) -> FnNumberVar {
    let mut param: Vec<Box<dyn Any>> = Vec::new();

    for (r, c) in list {
        param.push(Box::new(r));
        param.push(Box::new(c));
    }

    FnNumberVar("COUNTIFS", param)
}