You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "C:/Users/Fa/Desktop/test1.py", line 2, in
from docx import Document
ModuleNotFoundError: No module named 'docx'
the code ::
import datetime
from docx import Document
def create_shift_schedule(start_date, end_date, employees):
"""
Creates a table in Word with the automatically redistributed shifts.
Args:
start_date: The start date of the schedule.
end_date: The end date of the schedule.
employees: A list of employee names.
Returns:
A table in Word with the automatically redistributed shifts.
"""
Create a list of dates.
dates = []
for day in range(datetime.date.fromisoformat(start_date), datetime.date.fromisoformat(end_date) + 1):
dates.append(day)
Populate the table with the dates and employee names.
for i, date in enumerate(dates):
for j, employee in enumerate(employees):
table.cell(i, j).text = date
table.cell(i, j + 1).text = employee
Get the list of employees on vacation.
vacation_employees = []
for employee in employees:
if employee in vacation_employees:
continue
vacation_start_date = input("Enter the start date of the employee's vacation (YYYY-MM-DD): ")
vacation_end_date = input("Enter the end date of the employee's vacation (YYYY-MM-DD): ")
vacation_employees.append((employee, vacation_start_date, vacation_end_date))
Exclude employees on vacation from the shift schedule.
for employee, vacation_start_date, vacation_end_date in vacation_employees:
for i in range(len(dates)):
if dates[i] >= vacation_start_date and dates[i] <= vacation_end_date:
table.cell(i, j + 1).text = ""
Save the Word document.
doc.save("shift_schedule.docx")
if name == "main":
Get the start and end dates from the user.
start_date = input("Enter the start date (YYYY-MM-DD): ")
end_date = input("Enter the end date (YYYY-MM-DD): ")
Get the list of employee names from the user.
employees = input("Enter the list of employee names (separated by commas): ").split(",")
the error
Traceback (most recent call last):
File "C:/Users/Fa/Desktop/test1.py", line 2, in
from docx import Document
ModuleNotFoundError: No module named 'docx'
the code ::
import datetime
from docx import Document
def create_shift_schedule(start_date, end_date, employees):
"""
Creates a table in Word with the automatically redistributed shifts.
Args:
start_date: The start date of the schedule.
end_date: The end date of the schedule.
employees: A list of employee names.
Returns:
A table in Word with the automatically redistributed shifts.
"""
Create a list of dates.
dates = []
for day in range(datetime.date.fromisoformat(start_date), datetime.date.fromisoformat(end_date) + 1):
dates.append(day)
Create a Word document.
doc = Document()
Create a table in the Word document.
table = doc.add_table(rows=len(dates), cols=len(employees) + 1)
Populate the table with the dates and employee names.
for i, date in enumerate(dates):
for j, employee in enumerate(employees):
table.cell(i, j).text = date
table.cell(i, j + 1).text = employee
Get the list of employees on vacation.
vacation_employees = []
for employee in employees:
if employee in vacation_employees:
continue
vacation_start_date = input("Enter the start date of the employee's vacation (YYYY-MM-DD): ")
vacation_end_date = input("Enter the end date of the employee's vacation (YYYY-MM-DD): ")
vacation_employees.append((employee, vacation_start_date, vacation_end_date))
Exclude employees on vacation from the shift schedule.
for employee, vacation_start_date, vacation_end_date in vacation_employees:
for i in range(len(dates)):
if dates[i] >= vacation_start_date and dates[i] <= vacation_end_date:
table.cell(i, j + 1).text = ""
Save the Word document.
doc.save("shift_schedule.docx")
if name == "main":
Get the start and end dates from the user.
start_date = input("Enter the start date (YYYY-MM-DD): ")
end_date = input("Enter the end date (YYYY-MM-DD): ")
Get the list of employee names from the user.
employees = input("Enter the list of employee names (separated by commas): ").split(",")
Create the shift schedule.
create_shift_schedule(start_date, end_date, employees)
The text was updated successfully, but these errors were encountered: