import pandas as pd from docx import Document def populatechambers(excelpath, docpath,…
- User
import pandas as pd from docx import Document
def populate_chambers(excel_path, doc_path, output_path): try: print("Loading Excel data...") df = pd.read_excel(excel_path) print(f"Excel data loaded: {len(df)} rows")
codeprint("Loading Word document...") doc = Document(doc_path) tables = doc.tables print(f"Total tables found in document: {len(tables)}") # Check if tables exist in the document if not tables: print("Error: No tables found in document.") return # Iterate through each row of the DataFrame for i, row in df.iterrows(): # If we have a table for this row if i < len(tables): table = tables[i] # Ensure that the table has enough rows if len(table.rows) >= 15: try: # Fill the cells from the row in the DataFrame table.cell(4, 0).text = str(row['Client Name ']) # Client Name table.cell(24, 0).text = str(row['Description (in 500 words)']) # Description table.cell(14, 0).text = str(row['Value ']) # Matter/Case Overview table.cell(20, 0).text = str(row['Lead partners']) # Lead Partner #table.cell(12, 0).text = str(row['Team Members']) # Team Members table.cell(22, 0).text = str(row['Other Firms/counsels Involved']) # Other Involved Firms # Directly take the current status or date, treating it as a string # table.cell(16, 0).text = str(row['Current Status (ongoing / completed )']) # Directly capture the status or date print(f"Matter {i + 1} populated successfully.") except IndexError as e: print(f"Error: Table {i + 1} has fewer rows than expected. Skipping entry. {e}") else: print(f"Warning: Table {i + 1} has only {len(table.rows)} rows. Expected at least 18.") else: print(f"Warning: No more tables available in the document for extra rows in Excel. Extra rows: {len(df) - len(tables)}") # Save the updated document doc.save(output_path) print("Document updated successfully!") except Exception as e: print(f"Unexpected error: {e}") - Assistant
- User
not filling data in yes wala form
- Assistant
- User
- Assistant
- User
Excel data loaded: 23 rows Loading Word document for 'Yes' forms... Total tables found in the 'Yes' document: 3 Loading Word document for 'No' forms... Total tables found in the 'No' document: 3 Unexpected error: '_Cell' object has no attribute 'clear'
- Assistant