这是一个简化办公工作的高效工具库,专注于提供常见任务的快捷处理能力。它包含以下核心功能模块:1. 数据库操作:支持快速查询、插入、更新、删除等操作,让开发者仅需1到3行代码即可完成复杂的数据库交互。2. Excel处理:提供灵活的Excel读写、数据筛选、格式化功能,轻松生成或解析复杂表格。3. 邮件发送:集成邮件发送功能,支持多附件、HTML内容等自定义配置,邮件交互更轻松。4. 日期与时间戳格式转换:高效支持各种日期格式与时间戳的快速转换与计算,适配多场景需求。5. 文件操作:一键实现文件的移动、复制、重命名等常见操作,提升文件管理效率。通过整合这些功能,工具库致力于帮助用户在最少的代码量下完成繁琐任务,极大提升办公自动化与开发效率。
Project description
wei_office_simptool
wei_office_simptool 一个用于简化办公工作的工具库,提供了数据库操作、Excel 处理、邮件发送、日期时间戳的格式转换、文件移动等常见功能,实现1到3行代码完成相关处理的快捷操作。
🔌安装与升级
使用以下命令安装 wei_office_simptool:
pip install wei_office_simptool
使用以下命令升级 wei_office_simptool:
pip install wei_office_simptool --upgrade
🔧功能
1. MySQLDatabase 类
主要用于Mysql数据库的快速连接
from wei_office_simptool import MySQLDatabase
📌MySQL 连接配置
mysql_config = {
'host': 'your_host',
'user': 'your_user',
'password': 'your_password',
'database': 'your_database'
}
✏️创建 MySQLDatabase 对象
db = MySQLDatabase(mysql_config)
📥插入数据
insert_query = "INSERT INTO your_table (column1, column2) VALUES (%s, %s)"
insert_params = ("value1", "value2")
db.execute_query(insert_query, insert_params)
🔍查询数据
select_query = "SELECT * FROM your_table"
results = db.fetch_query(select_query)
for row in results:
print(row)
⌛更新数据
update_query = "UPDATE your_table SET column1 = %s WHERE column2 = %s"
update_params = ("new_value", "value2")
db.execute_query(update_query, update_params)
🔪删除数据
delete_query = "DELETE FROM your_table WHERE column1 = %s"
delete_params = ("new_value",)
db.execute_query(delete_query, delete_params)
🚪关闭连接
db.close()
SQLAI智能聊天机器人
from wei_office_simptool import SQLManager
# 示例代码
cfg = {
'user': 'root',
'password': '你的密码',
'host': '127.0.0.1',
'database': 'mlcorpus'
}
db = SQLManager.MySQLDatabase(cfg)
db.run_ai_chatbot(chat_history_size=5, system_msg="System: You are a helpful AI assistant.")
2. Excel 相关类
提供完整的 Excel 文件创建、读取、写入和操作功能。
from pathlib import Path
from wei_office_simptool import ExcelManager, ExcelHandler, OpenExcel, ExcelOperation, quick_excel
2.1 ExcelManager 类(推荐使用)
轻量级 Excel 工作簿管理类,基于 openpyxl,无需安装 Excel 应用。
特性:
- 自动创建不存在的文件
- 支持多工作表操作
- 快速读写数据
- 自动应用样式
- DataFrame 支持
from wei_office_simptool import ExcelManager
# 创建或打开文件
wb = ExcelManager("data.xlsx")
# 写入数据(自动应用样式)
wb.write_sheet("Sheet1", [["Name", "Age"], ["Alice", 25]], start_row=1, start_col=1)
# 快速写入(自动计算范围)
wb.fast_write("Sheet1", [["Bob", 30]], start_row=3, start_col=1)
# 读取数据
data = wb.read_sheet("Sheet1", 1, 1)
# 使用上下文管理器(自动保存)
with ExcelManager("data.xlsx") as wb:
wb.fast_write("Sheet1", [[1, 2], [3, 4]], 1, 1)
# 保存并关闭
wb.save()
wb.close()
DataFrame 支持:
import pandas as pd
from wei_office_simptool import ExcelManager
df = pd.DataFrame({"Name": ["Alice", "Bob"], "Age": [25, 30]})
# DataFrame 写入 Excel
with ExcelManager("data.xlsx") as wb:
wb.write_dataframe("Sheet1", df)
# Excel 读取为 DataFrame
with ExcelManager("data.xlsx") as wb:
df = wb.read_dataframe("Sheet1")
工作表管理:
from wei_office_simptool import ExcelManager
wb = ExcelManager("data.xlsx")
# 创建新工作表
wb.create_sheet("NewSheet")
# 获取工作表信息
info = wb.get_sheet_info("Sheet1")
print(info)
# 复制工作表
wb.copy_sheet("Sheet1", "Sheet1_Copy")
# 删除工作表
wb.delete_sheet("OldSheet")
2.2 快速创建与读取
一行代码完成常用操作:
from wei_office_simptool import quick_excel, read_excel_quick
# 快速创建并写入数据
wb = quick_excel("data.xlsx", [["Name", "Age"], ["Alice", 25]])
# 快速读取为列表
data = read_excel_quick("data.xlsx")
# 快速读取为 DataFrame
df = read_excel_quick("data.xlsx", as_dataframe=True)
2.3 ExcelHandler 类(兼容版)
面向已有文件的读取/写入工具,为兼容性保留。
from wei_office_simptool import ExcelHandler
eh = ExcelHandler("data.xlsx")
# 写入指定范围
eh.excel_write("Sheet1", [[1, 2], [3, 4]], 1, 1, 2, 2)
# 读取指定范围
data = eh.excel_read("Sheet1", 1, 1, 2, 2)
# 另存为
eh.excel_save_as("output.xlsx")
# 关闭
eh.excel_quit()
2.4 OpenExcel 类(Excel 应用操作)
通过 Excel 应用打开工作簿,适合需要 RefreshAll 的场景。 注意:需要安装 Microsoft Excel
from wei_office_simptool import OpenExcel
# 使用上下文管理器自动保存
with OpenExcel("data.xlsx").my_open() as wb:
wb.fast_write("Sheet1", [[1, 2], [3, 4]], 1, 1)
# 刷新数据连接(需要 Excel 应用)
with OpenExcel("data.xlsx").open_save_Excel() as appwb:
appwb.api.RefreshAll()
# 列出工作表并按关键词过滤
sheets = OpenExcel("data.xlsx").file_show(filter=["sheet", "报表"])
print(sheets)
2.5 ExcelOperation 类(数据处理)
提供数据拆分、合并等高级操作。
from wei_office_simptool import ExcelOperation
# 按工作表拆分为多个文件
op = ExcelOperation("data.xlsx", "output_folder")
files = op.split_table()
# 合并多个文件
op.merge_tables(["file1.xlsx", "file2.xlsx"], "merged.xlsx")
# 转换为 CSV
csv_path = op.convert_to_csv()
2.6 完整流水线示例
from pathlib import Path
from wei_office_simptool import ExcelManager, OpenExcel, ExcelOperation
base = Path.cwd()
f = str(base / "pipeline.xlsx")
# 1) 创建并写入数据
with ExcelManager(f) as wb:
wb.fast_write("Sheet1", [["Name", "Age"], ["Alice", 25], ["Bob", 30]], 1, 1)
# 2) 通过 Excel 应用刷新(需要本机 Excel)
with OpenExcel(f).open_save_Excel() as appwb:
appwb.api.RefreshAll()
# 3) 拆分工作表到单文件
op = ExcelOperation(f, str(base / "output"))
op.split_table()
# 4) 转换为 CSV
csv_file = op.convert_to_csv()
3. eSend 类
用于发送邮件。
from wei_office_simptool import eSend
# 示例代码
email_sender = eSend(sender,receiver,username,password,smtpserver='smtp.126.com')
email_sender.send_email(subject='Your Subject', e_content='Your Email Content', file_paths=['/path/to/file/'], file_names=['attachment.txt'])
4. DateFormat 类
用于获取最近的时间处理。
from wei_office_simptool import DateFormat
# 示例代码
#timeclass:1日期 date 2时间戳 timestamp 3时刻 time 4datetime
#获取当日的日期字符串
x=DateFormat(interval_day=0,timeclass='date').get_timeparameter(Format="%Y-%m-%d")
print(x)
# 格式化df的表的列属性
df = DateFormat(interval_day=0,timeclass='date').datetime_standar(df, '日期')
5. FileManagement 类
用于文件移动并且重命名。
#latest_folder2 当前目录
#destination_directory 目标目录
#target_files2 文件名
#add_prefix 重命名去除数字
#file_type 文件类型
FileManagement().copy_files(latest_folder2, destination_directory, target_files2, rename=True,file_type="xls")
#寻找最新文件夹
latest_folder = FileManagement().find_latest_folder(base_directory)
6. StringBaba 类
用于清洗字符串。
from wei_office_simptool import StringBaba
str="""
萝卜
白菜
"""
formatted_str =StringBaba(str1).format_string_sql()
7. TextAnalysis 类
用于进行词频分析。
from wei_office_simptool import TextAnalysis
# 示例用法
data = {
'Category': ['A', 'A', 'B', 'D', 'C'],
'Text': [
'我爱自然语言处理',
'自然语言处理很有趣',
'机器学习是一门很有前途的学科',
'我对机器学习很感兴趣',
'数据科学包含很多有趣的内容'
]
}
df = pd.DataFrame(data)
ta = TextAnalysis(df)
result = ta.get_word_freq(group_col='Category', text_col='Text', agg_func=' '.join)
word_freqs = result['word_freq'].tolist()
titles = result['Category'].tolist()
ta.plot_wordclouds(word_freqs, titles)
8. ChatBot类
0.0.29新增,用于连接Ollama的AI接口
from wei_office_simptool import ChatBot
bot = ChatBot(api_url='http://localhost:11434/api/chat')
print("开始聊天(输入 'exit' 退出,输入 'new' 新建聊天)")
while True:
user_input = input("你: ")
if user_input.lower() == 'exit':
break
elif user_input.lower() == 'new':
bot.start_new_chat()
continue
# 默认使用流式响应,可以根据需要选择非流式响应
bot.send_message(user_input, stream=True)
print("聊天结束。")
9 DailyEmailReport 类
用于发送每日报告邮件,支持HTML和纯文本格式。
from wei_office_simptool import DailyEmailReport
# 初始化 DailyEmailReport 实例
email_reporter = DailyEmailReport(
email_host='smtp.example.com',
email_port=465,
email_username='your_email@example.com',
email_password='your_password'
)
# 添加收件人
email_reporter.add_receiver('recipient@example.com')
# 发送纯文本邮件
text_content = """
Hello,
Here is your daily report.
[Insert your report content here.]
Regards,
Your Name
"""
email_reporter.send_daily_report("Daily Report", text_content)
# 发送HTML邮件 - 方式1
html_content = """
<html>
<body>
<h1>Daily Report</h1>
<p>Hello,</p>
<p>Here is your <b>daily report</b>.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<p>Regards,<br>
Your Name</p>
</body>
</html>
"""
email_reporter.send_daily_report("HTML Report", html_content, is_html=True)
# 发送HTML邮件 - 方式2
email_reporter.send_daily_report("HTML Report", html_content=html_content)
Contributing / 参与贡献
English: We welcome contributions! If you have any questions, suggestions, or improvements, please feel free to:
- Submit an Issue - Report bugs or request features
- Submit a Pull Request - Contribute code
中文: 我们欢迎并感谢您的贡献!如果您有任何问题、建议或改进,请随时:
- 提交 Issue - 报告 bug 或提出功能建议
- 提交 Pull Request - 贡献代码
License / 许可证
Copyright © 2026 Ethan Wilkins. All rights reserved.
English: This project is licensed under the MIT License.
中文: 本项目采用 MIT 许可证 开源许可。
MIT License
Copyright (c) 2026 Ethan Wilkins
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
免责声明 / Disclaimer:
English: This software is provided "as is", without warranty of any kind, express or implied. The authors or copyright holders shall not be liable for any claims, damages, or other liabilities arising from the use of this software.
中文: 本软件按"原样"提供,不附带任何明示或暗示的担保。在任何情况下,作者或版权所有者均不对因使用本软件而产生的任何索赔、损害或其他责任承担责任。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wei_office_simptool-0.2.5.tar.gz.
File metadata
- Download URL: wei_office_simptool-0.2.5.tar.gz
- Upload date:
- Size: 35.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31977f3849377b20937a791a21606377dfc7302947dd3a0b0f8c3c7d769787bd
|
|
| MD5 |
a41b0e922319c3a9377ae2d3f51aa274
|
|
| BLAKE2b-256 |
a8659d9bcaad476b8acca1db785b935db1384909aeb1bfd7ecf8b19d537d4b35
|
File details
Details for the file wei_office_simptool-0.2.5-py3-none-any.whl.
File metadata
- Download URL: wei_office_simptool-0.2.5-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8c0d400452bda63614bc19ebf5afb85098b7143e9594b4030cee7ff0f2af420
|
|
| MD5 |
980e637e79d95cc487bb37e06c34b649
|
|
| BLAKE2b-256 |
a878964d5c83fc32bdc91faecc0797a982e44be018d6443620155e0d11c9f76a
|