| name | xlsx |
| description | Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .csv, or .tsv file; create a new spreadsheet from scratch or from other data sources; or convert tabular data. If the user mentions a spreadsheet file by name or path — e.g., 'the xlsx in my downloads' — use this skill. |
XLSX Creation, Editing, and Analysis in EverFern
Overview
A user may ask you to create, edit, or analyze the contents of an .xlsx file. On Windows, use Python libraries like pandas and openpyxl. Use absolute Windows paths (e.g., C:\Users\Username\Downloads\data.xlsx).
Reading and Analyzing Data
Data Analysis with pandas
For data analysis, visualization, and basic operations, use pandas:
import pandas as pd
df = pd.read_excel(r'C:\path\to\file.xlsx')
all_sheets = pd.read_excel(r'C:\path\to\file.xlsx', sheet_name=None)
print(df.head())
print(df.info())
print(df.describe())
df.to_excel(r'C:\path\to\output.xlsx', index=False)
Modifying Excel Files
If the user wants you to edit existing spreadsheets while keeping formatting, or write formulas, use openpyxl.
CRITICAL: Use Formulas, Not Hardcoded Values
Always use Excel formulas instead of calculating values in Python and hardcoding them. This ensures the spreadsheet remains dynamic and updateable.
❌ WRONG - Hardcoding Calculated Values
total = df['Sales'].sum()
sheet['B10'] = total
✅ CORRECT - Using Excel Formulas
sheet['B10'] = '=SUM(B2:B9)'
Common Workflows
Creating New Excel Files
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment
wb = Workbook()
sheet = wb.active
sheet['A1'] = 'Hello'
sheet['B1'] = 'World'
sheet.append(['Row', 'of', 'data'])
sheet['B2'] = '=SUM(A1:A10)'
sheet['A1'].font = Font(bold=True, color='FF0000')
sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')
sheet['A1'].alignment = Alignment(horizontal='center')
sheet.column_dimensions['A'].width = 20
wb.save(r'C:\path\to\output.xlsx')
Editing Existing Excel Files
from openpyxl import load_workbook
wb = load_workbook(r'C:\path\to\existing.xlsx')
sheet = wb.active
for sheet_name in wb.sheetnames:
print(f"Sheet: {sheet_name}")
sheet['A1'] = 'New Value'
sheet.insert_rows(2)
sheet.delete_cols(3)
new_sheet = wb.create_sheet('NewSheet')
new_sheet['A1'] = 'Data'
wb.save(r'C:\path\to\modified.xlsx')
Best Practices
Library Selection
- pandas: Best for data analysis, bulk operations, and simple data export
- openpyxl: Best for complex formatting, formulas, and Excel-specific features
Working with openpyxl
- Cell indices are 1-based (row=1, column=1 refers to cell A1)
- To read calculated values instead of formula strings:
load_workbook('file.xlsx', data_only=True).
- Warning: If opened with
data_only=True and saved, formulas are replaced with values and permanently lost. Only use this for reading.
- For large files: Use
read_only=True for reading.
Working with pandas
- Specify data types to avoid inference issues:
pd.read_excel('file.xlsx', dtype={'id': str})
- For large files, read specific columns:
pd.read_excel('file.xlsx', usecols=['A', 'C', 'E'])
- Handle dates properly:
pd.read_excel('file.xlsx', parse_dates=['date_column'])
Formula Checklist