admin管理员组

文章数量:1319479

I'm using Docx and Pandas to create a program that copies data from an Excel sheet to a Word document. I've been running into some errors in VSCode, where I am either thrown a ModuleNotFound error with pandas and docx, or I am given no output with my program. I am assuming there is an issue with how I'm running something, but I can not find it. It would be greatly appreciated if someone could let me know why there is no output, as well as why I am randomly thrown this error.

For reference, my pip list shows that docx and pandas are both installed and up to date.

I am also looking for a better way to code this! All help is greatly appreciated!

import pandas as pd
from docx import Document
def assignteam(spreadsheet, tabname, teamnum):
    df = pd.read_excel(spreadsheet, sheet_name=tabname)

    check_team = df[df["Team Name"] == teamnum]
    print("hello i work")

    return check_team 
print("hello i work")
def one_pager(check_team, teamnum):
    doc = Document()
    doc.add_heading(f'Team {teamnum} Data', level=1)
    table = doc.add_table(rows = 1, cols = len(check_team.columns)) 
    table.style = 'Table Grid'
    print("hello i work")

    
    header = table.rows[0].cells 
    for x, col in enumerate(check_team.columns):
        header[x].text = str(col)
    print("hello i work pt2")

    
    for index, row in check_team.iterrows(): 
        cells = table.add_row().cells
        for x, value in enumerate(row):
            cells[x].text = str(value)
    print("hello i work pt3")

    doc.save(f'Team_{teamnum}.docx') 

def main():
    # Self-explanatory
    spreadsheet = input("Enter the path to the spreadsheet: ") 
    tabname = input("Enter the tab name: ")
    teamnum = input("Enter team number: ")

    totaldat = assignteam(spreadsheet, tabname, teamnum)
    
    if totaldat.empty:
        print(f"No data found for team {teamnum}.")
    else:
        one_pager(totaldat, teamnum)
        print(f"Data for team {teamnum} has been written to Team_{teamnum}.docx")
    ```

本文标签: