Python代码实现: 1. 创建一个需求管理excel,如果已经存在则直接打开,可添加多条需求,A列需求序号,B列需求内容,C列需求提出人, D列需求状态(open/close),E列需求提出时间,F列需求关闭时间 2. 可手工从界面添加多条数据 3. 可根据C列需求提出人和D列需求状态查询excel中的需求 4. 可以修改指定需求提出人且指定的状态为open的需求的状态,同时修改该需求的需求关闭时间为当前时间 5. 可以删除需求提出人为指定人且需求状态为close的需求 6. 可以统计出各个提出人open或者close需求的数量
时间: 2023-10-17 16:41:37 浏览: 75
以下是实现您所描述功能的Python代码:
```python
import openpyxl
from openpyxl import Workbook
from openpyxl.utils import get_column_letter
from openpyxl.styles import Font
from datetime import datetime
# 创建或打开需求管理excel
def open_excel(file_path):
try:
workbook = openpyxl.load_workbook(file_path)
except FileNotFoundError:
workbook = Workbook()
workbook.save(file_path)
workbook = openpyxl.load_workbook(file_path)
return workbook.active
# 添加需求
def add_requirement(sheet, req_num, req_content, req_owner):
row_num = sheet.max_row + 1
sheet.cell(row=row_num, column=1).value = req_num
sheet.cell(row=row_num, column=2).value = req_content
sheet.cell(row=row_num, column=3).value = req_owner
sheet.cell(row=row_num, column=4).value = 'open'
sheet.cell(row=row_num, column=5).value = datetime.now()
# 查询需求
def query_requirements(sheet, req_owner=None, req_status=None):
result = []
for row in sheet.iter_rows(min_row=2, values_only=True):
if (not req_owner or row[2] == req_owner) and (not req_status or row[3] == req_status):
result.append(row[0:3])
return result
# 修改需求状态和关闭时间
def modify_requirement(sheet, req_owner, req_status):
current_time = datetime.now()
for row in sheet.iter_rows(min_row=2):
if row[2].value == req_owner and row[3].value == 'open':
row[3].value = req_status
row[5].value = current_time
# 删除需求
def delete_requirements(sheet, req_owner):
rows_to_delete = []
for row in sheet.iter_rows(min_row=2):
if row[2].value == req_owner and row[3].value == 'close':
rows_to_delete.append(row)
for row in rows_to_delete:
sheet.delete_rows(row[0].row)
# 统计需求数量
def count_requirements(sheet, req_status):
count = 0
for row in sheet.iter_rows(min_row=2):
if row[3].value == req_status:
count += 1
return count
# 手动添加需求
def manual_add_requirements(sheet):
print("请输入需求信息(输入exit退出):")
while True:
req_num = input("需求序号:")
if req_num.lower() == "exit":
break
req_content = input("需求内容:")
req_owner = input("需求提出人:")
add_requirement(sheet, req_num, req_content, req_owner)
# 测试代码
file_path = '需求管理.xlsx'
sheet = open_excel(file_path)
# 手动添加需求
manual_add_requirements(sheet)
# 查询需求
print("\n查询结果:")
results = query_requirements(sheet, req_owner='张三', req_status='open')
for result in results:
print(result)
# 修改需求状态和关闭时间
modify_requirement(sheet, req_owner='张三', req_status='close')
# 删除需求
delete_requirements(sheet, req_owner='张三')
# 统计需求数量
open_count = count_requirements(sheet, req_status='open')
close_count = count_requirements(sheet, req_status='close')
print("\nopen需求数量:", open_count)
print("close需求数量:", close_count)
# 保存并关闭excel文件
sheet.parent.save(file_path)
sheet.parent.close()
```
请确保在运行代码之前已安装openpyxl库(`pip install openpyxl`)。此代码可以创建或打开名为"需求管理.xlsx"的Excel文件,并实现您所描述的功能。您可以根据需要进行修改和扩展。
阅读全文