
import pandas as pd
import os

file1 = r"c:\Users\WIN10\Desktop\work\11th-week\法律风险提示-new\市监局-lawRisk-backend\风险提示表（空白）.xlsx"
file2 = r"c:\Users\WIN10\Desktop\work\11th-week\法律风险提示-new\市监局-lawRisk-backend\data\template\风险提示表 模板.xlsx"

def get_head_rows(filepath):
    try:
        # Read without header to get raw data
        df = pd.read_excel(filepath, header=None, nrows=10)
        # Convert NaN to empty string for cleaner output
        df = df.fillna("")
        return df.values.tolist()
    except Exception as e:
        return [f"Error: {e}"]

rows1 = get_head_rows(file1)
rows2 = get_head_rows(file2)

result_lines = []
result_lines.append(f"File 1: {os.path.basename(file1)}")
for i, row in enumerate(rows1):
    result_lines.append(f"Row {i}: {row}")
result_lines.append("-" * 20)
result_lines.append(f"File 2: {os.path.basename(file2)}")
for i, row in enumerate(rows2):
    result_lines.append(f"Row {i}: {row}")
result_lines.append("-" * 20)

with open("comparison_result.txt", "w", encoding="utf-8") as f:
    f.write("\n".join(str(l) for l in result_lines))
