1.6 KiB
1.6 KiB
Spreadsheet Manipulation Skill (xlsx)
Overview
This skill guides agents in manipulating Excel (.xlsx) spreadsheets using Python.
Primary libraries: openpyxl (structure-preserving read/write), pandas (data transformation).
Never use any other third-party libraries.
Common Workflow
- Explore the input file: list sheets, inspect headers, check dimensions.
- Write
solution.pywithINPUT_PATHandOUTPUT_PATHdefined at the top. - Execute
python solution.pyand verify the output file was created. - Confirm the target cells/range contain the expected values.
Library Selection
| Use case | Library |
|---|---|
| Preserve formulas, formatting, named ranges | openpyxl |
| Bulk data transformation, aggregation, sorting | pandas → write back with openpyxl |
| Simple cell read/write | openpyxl |
Warning: pandas.to_excel() silently destroys existing formulas and named ranges.
When writing back to a spreadsheet that contains formulas, always use openpyxl.save().
solution.py Template
import openpyxl
import pandas as pd
INPUT_PATH = "..." # set to the actual input path
OUTPUT_PATH = "..." # set to the actual output path
wb = openpyxl.load_workbook(INPUT_PATH)
ws = wb.active # or wb["SheetName"]
# --- perform manipulation ---
wb.save(OUTPUT_PATH)
Output Requirements
- Save the result to
OUTPUT_PATH. - Do not hardcode row counts or column letters — iterate over actual rows in the workbook.
- Preserve sheets and cells not mentioned in the instruction.