python代码: 1. 创建一个需求管理excel,如果已经存在则直接打开,可添加多条需求,A列需求序号,B列需求内容,C列需求提出人,D列需求状态(open/close),E列需求提出时间,F列需求关闭时间 2. 可根据C列需求提出人和D列需求状态查询excel中的需求 3. 可以修改指定需求提出人且指定的状态为open的需求的状态,同时修改该需求的需求关闭时间为当前时间 4. 可以删除需求提出人为指定人且需求状态为close的需求 5. 可以统计出open或者close需求的数量
时间: 2023-10-17 22:31:58 浏览: 51
2023年泰迪杯数据挖掘挑战赛B题订单分析与需求预测+python源码(示例数据)
5星 · 资源好评率100%
以下是实现这些功能的Python代码,需要先安装openpyxl库:
```python
import openpyxl
import datetime
class RequirementManagement:
def __init__(self, excel_path):
self.excel_path = excel_path
self.workbook = None
self.sheet = None
self.requirements = []
def open_excel(self):
try:
self.workbook = openpyxl.load_workbook(self.excel_path)
except FileNotFoundError:
self.workbook = openpyxl.Workbook()
self.sheet = self.workbook.active
self.sheet.title = '需求管理'
self.sheet.append(['需求序号', '需求内容', '需求提出人', '需求状态', '需求提出时间', '需求关闭时间'])
for row in self.sheet.iter_rows(min_row=2, values_only=True):
self.requirements.append({
'序号': row[0],
'内容': row[1],
'提出人': row[2],
'状态': row[3],
'提出时间': row[4],
'关闭时间': row[5]
})
def add_requirement(self, content, proposer):
last_row = len(self.requirements) + 1
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.sheet.cell(row=last_row, column=1, value=last_row - 1)
self.sheet.cell(row=last_row, column=2, value=content)
self.sheet.cell(row=last_row, column=3, value=proposer)
self.sheet.cell(row=last_row, column=4, value='open')
self.sheet.cell(row=last_row, column=5, value=now)
self.sheet.cell(row=last_row, column=6, value='')
self.requirements.append({
'序号': last_row - 1,
'内容': content,
'提出人': proposer,
'状态': 'open',
'提出时间': now,
'关闭时间': ''
})
self.workbook.save(self.excel_path)
def search_requirements(self, proposer=None, status=None):
results = []
for req in self.requirements:
if (proposer is None or req['提出人'] == proposer) and (status is None or req['状态'] == status):
results.append(req)
return results
def modify_requirement(self, proposer, new_status):
for req in self.requirements:
if req['提出人'] == proposer and req['状态'] == 'open':
req['状态'] = new_status
req['关闭时间'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
row = req['序号'] + 1
self.sheet.cell(row=row, column=4, value=new_status)
self.sheet.cell(row=row, column=6, value=req['关闭时间'])
self.workbook.save(self.excel_path)
def delete_requirements(self, proposer):
rows_to_delete = []
for req in self.requirements:
if req['提出人'] == proposer and req['状态'] == 'close':
rows_to_delete.append(req['序号'] + 1)
for row in reversed(rows_to_delete):
self.sheet.delete_rows(row, 1)
del self.requirements[row - 2]
self.workbook.save(self.excel_path)
def count_requirements(self, status):
count = 0
for req in self.requirements:
if req['状态'] == status:
count += 1
return count
```
使用方法示例:
```python
rm = RequirementManagement('需求管理.xlsx')
rm.open_excel()
rm.add_requirement('这是一条需求', '张三')
rm.add_requirement('另一条需求', '李四')
results = rm.search_requirements(proposer='张三')
print(results)
rm.modify_requirement('张三', 'close')
rm.delete_requirements('张三')
open_count = rm.count_requirements('open')
close_count = rm.count_requirements('close')
print(f'open需求数量:{open_count}')
print(f'close需求数量:{close_count}')
```
阅读全文