Skip to content

Commandline Interfaces

Commandline Interfaces.

load(p_toml, p_xlsx, p_out, engine=OpenPYXL)

Load configuration to a spreadsheet and save it to a file.

Parameters:

Name Type Description Default
p_toml Path

Path to the TOML file.

required
p_xlsx Path

Path to the XLSX file.

required
p_out Path

Path to the output file.

required
engine Engine

Workbook engine to use.

OpenPYXL

Returns:

Type Description
Path to the output file.
Source code in named_xlsx/cli.py
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
def load(p_toml: Path, p_xlsx: Path, p_out: Path, engine: Engine = OpenPYXL) -> Path:
    """
    Load configuration to a spreadsheet and save it to a file.

    Parameters
    ----------
    p_toml
        Path to the TOML file.
    p_xlsx
        Path to the XLSX file.
    p_out
        Path to the output file.
    engine
        Workbook engine to use.

    Returns
    -------
    Path to the output file.

    """
    cfg = {
        name: value
        for sheet, mapping in toml.load(p_toml).items()
        for name, value in mapping.items()
    }
    shutil.copy(p_xlsx, p_out)
    with closing(engine.from_file(p_out)) as m:
        for addr, vals in cfg.items():
            m.write_via_name(addr, vals)
        m.save()

    return p_out