The Excel Parser skill is used to extract content from and write content to Excel files, supporting multiple Excel formats.
Compatibility
- Python 3.7+
- Dependencies:
python-dotenv,python-calamine - Alternative dependencies:
xlwings(for all Excel formats)
Usage
Basic Usage
from excel_parser import ExcelParser, process_excel, write_excel_file, update_excel_file
# 方法1: 使用ExcelParser类
parser = ExcelParser()
Read Excel files
result = parser.parse_excel('path/to/file.xlsx')
Get text format outputtext = parser.parse_excel_to_text('path/to/file.xlsx')
Write Excel fileswrite_data = { "sheets": [ { "name": "Sheet1", "rows": [["A1", "B1"], ["A2", "B2"]], "merged_cells": [ { "start_row": 0, "end_row": 0, "start_col": 0, "end_col": 1 } ] } ] } parser.write_excel('output.xlsx', write_data)
Update Excel filesparser.update_excel('existing_file.xlsx', write_data)
Method 2: Use convenience functions Read Excel filesresult = process_excel('path/to/file.xlsx')
Write Excel fileswrite_result = write_excel_file('output.xlsx', write_data)
Update Excel filesupdate_result = update_excel_file('existing_file.xlsx', write_data)
### 返回结果格式
```python
{
"text": "格式化的文本内容",
"sheets": [
{
"name": "Sheet1",
"rows": [["A1", "B1"], ["A2", "B2"]],
"row_count": 2,
"column_count": 2
}
],
"sheet_count": 1,
"total_cells": 4,
"engine": "python-calamine"
}
Supported file formats
- .xls (Excel 97-2003)
- .xlsx, .xlsm (Excel 2007+)
- .xltx, .xltm (Excel templates)
Environment variable configuration
Create .env file:
# 最大行数限制,默认100行
EXCEL_MAX_ROWS=100
# 是否保留空行,默认false
EXCEL_KEEP_EMPTY_ROWS=false
Detailed documentation
For more usage examples and troubleshooting information, see README.md。