Skip to main content

📊 Excel API Reference

This page is currently only available in Chinese. Please switch to 简体中文 for the full content.

📊 Excel API Reference

Sub-package: poexcel | Install: pip install poexcel Import: import office or import poexcel

Function Overview

FunctionDescriptionDifficulty
fake2excelAuto-generate mock data
merge2excelMerge multiple Excel files⭐⭐
sheet2excelSplit sheets⭐⭐
merge2sheetMerge multiple sheets⭐⭐
find_excel_dataSearch Excel⭐⭐
split_excel_by_columnSplit by column⭐⭐⭐
excel2pdfExcel to PDF

fake2excel

Auto-create an Excel file with mock data.

Function signature:

office.excel.fake2excel(
columns=['name'],
rows=1,
path='./fake2excel.xlsx',
language='zh_CN'
)

Parameters:

ParameterTypeRequiredDefaultDescription
columnslistNo['name']List of column names
rowsintNo1Number of rows to generate
pathstrNo'./fake2excel.xlsx'Output file path
languagestrNo'zh_CN'Data language ('zh_CN' or 'english')

Examples:

import office

# Example 1: Generate a simple Excel
office.excel.fake2excel(columns=['name'], rows=10, path='names.xlsx')

# Example 2: Multi-column user data
office.excel.fake2excel(
columns=['name', 'phone', 'email', 'address', 'company'],
rows=100,
path='users.xlsx'
)

# Example 3: English data
office.excel.fake2excel(
columns=['name', 'country', 'city'],
rows=50,
path='english_data.xlsx',
language='english'
)

merge2excel

Merge multiple Excel files into different sheets of one Excel.

office.excel.merge2excel(
dir_path,
output_file='merge2excel.xlsx'
)
office.excel.merge2excel(
dir_path='./excels/',
output_file='merged.xlsx'
)

sheet2excel

Split different sheets of one Excel into different Excel files.

office.excel.sheet2excel(
file_path,
output_path='./'
)

merge2sheet

Auto-merge multiple sheets from multiple Excel files into one Excel.

office.excel.merge2sheet(
dir_path,
output_sheet_name='Sheet1',
output_excel_name='merge2sheet'
)

find_excel_data

Search for specified content in Excel files.

office.excel.find_excel_data(
search_key,
target_dir
)
office.excel.find_excel_data(
search_key='Customer A',
target_dir='./excels/'
)

split_excel_by_column

Split an Excel file by the values of a specified column.

office.excel.split_excel_by_column(
filepath,
column,
worksheet_name=None
)
office.excel.split_excel_by_column(
filepath='sales_data.xlsx',
column=2
)

excel2pdf

Convert an Excel file to PDF format.

office.excel.excel2pdf(
excel_path,
pdf_path,
sheet_id=0
)
office.excel.excel2pdf(
excel_path='report.xlsx',
pdf_path='./output/report.pdf',
sheet_id=1
)
AI 办公效率课
35 讲 AI 自动化办公实战课用 Python + AI 处理 Excel、Word、PDF、邮件等办公场景。
去学习