#!/usr/bin/env python3 """Generated OfficeCLI script for headcount-q2.xlsx""" import json, subprocess, tempfile, os FILE = "headcount-q2.xlsx" def batch(commands): with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f: json.dump(commands, f) f.flush() result = subprocess.run( ["officecli", "batch", FILE, "--input", f.name], capture_output=True, text=True ) os.unlink(f.name) if result.returncode != 0: print(result.stderr or result.stdout) raise RuntimeError(f"Batch failed: {result.returncode}") print(result.stdout, end="") subprocess.run(["officecli", "create", FILE], check=True) # Turn 1: headcount-turn1 batch(json.loads('[\n {\n "command": "set",\n "path": "/Sheet1/A1",\n "props": {\n "value": "Department",\n "bold": "true",\n "fill": "4472C4",\n "font.color": "FFFFFF",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/B1",\n "props": {\n "value": "Current Headcount",\n "bold": "true",\n "fill": "4472C4",\n "font.color": "FFFFFF",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/C1",\n "props": {\n "value": "Open Roles",\n "bold": "true",\n "fill": "4472C4",\n "font.color": "FFFFFF",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D1",\n "props": {\n "value": "Monthly Salary Budget",\n "bold": "true",\n "fill": "4472C4",\n "font.color": "FFFFFF",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/A2",\n "props": {\n "value": "Engineering",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/B2",\n "props": {\n "value": "52",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/C2",\n "props": {\n "value": "6",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D2",\n "props": {\n "value": "487000",\n "type": "number",\n "numFmt": "$#,##0",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/A3",\n "props": {\n "value": "Sales",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/B3",\n "props": {\n "value": "31",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/C3",\n "props": {\n "value": "4",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D3",\n "props": {\n "value": "298000",\n "type": "number",\n "numFmt": "$#,##0",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/A4",\n "props": {\n "value": "Marketing",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/B4",\n "props": {\n "value": "18",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/C4",\n "props": {\n "value": "2",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D4",\n "props": {\n "value": "164000",\n "type": "number",\n "numFmt": "$#,##0",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/A5",\n "props": {\n "value": "Operations",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/B5",\n "props": {\n "value": "24",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/C5",\n "props": {\n "value": "1",\n "type": "number",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D5",\n "props": {\n "value": "201000",\n "type": "number",\n "numFmt": "$#,##0",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/A6",\n "props": {\n "value": "Total",\n "bold": "true",\n "fill": "D9E1F2",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/B6",\n "props": {\n "formula": "=SUM(B2:B5)",\n "bold": "true",\n "fill": "D9E1F2",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/C6",\n "props": {\n "formula": "=SUM(C2:C5)",\n "bold": "true",\n "fill": "D9E1F2",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D6",\n "props": {\n "formula": "=SUM(D2:D5)",\n "bold": "true",\n "fill": "D9E1F2",\n "numFmt": "$#,##0",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/col[A]",\n "props": {\n "width": "18"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/col[B]",\n "props": {\n "width": "20"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/col[C]",\n "props": {\n "width": "14"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/col[D]",\n "props": {\n "width": "24"\n }\n }\n]')) # Turn 2: headcount-turn2 batch(json.loads('[\n {\n "command": "set",\n "path": "/Sheet1/C3",\n "props": {\n "value": "5"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D3",\n "props": {\n "value": "312000"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/C6",\n "props": {\n "formula": "=SUM(C2:C5)"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D6",\n "props": {\n "formula": "=SUM(D2:D5)"\n }\n }\n]')) # Turn 3: headcount-turn3 batch(json.loads('[\n {\n "command": "add",\n "parent": "/Sheet1",\n "type": "col",\n "index": 4\n },\n {\n "command": "set",\n "path": "/Sheet1/D1",\n "props": {\n "value": "Target Headcount",\n "bold": "true",\n "fill": "4472C4",\n "font.color": "FFFFFF",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D2",\n "props": {\n "formula": "=B2+C2",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D3",\n "props": {\n "formula": "=B3+C3",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D4",\n "props": {\n "formula": "=B4+C4",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D5",\n "props": {\n "formula": "=B5+C5",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/D6",\n "props": {\n "formula": "=B6+C6",\n "bold": "true",\n "fill": "D9E1F2",\n "halign": "center",\n "border.all": "thin"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/col[D]",\n "props": {\n "width": "18"\n }\n },\n {\n "command": "set",\n "path": "/Sheet1/E6",\n "props": {\n "formula": "=SUM(E2:E5)"\n }\n }\n]')) subprocess.run(["officecli", "validate", FILE], check=True) print(f"\nDone: {FILE}")

AltStyle によって変換されたページ (->オリジナル) /