You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.8 KiB

import os
import openpyxl
# 文件路径
input_file = r'D:\计量经济学\计量实验资料及作业要求\计量实验资料及作业要求\图文帖子实验数据(新).xlsx'
output_file = r'D:\计量经济学\计量实验资料及作业要求\计量实验资料及作业要求\UGC回归数据.xlsx'
print("========================================")
print(" 检查Excel文件大小")
print("========================================")
print(f"输入文件: {input_file}")
print(f"输出文件: {output_file}")
print()
# 检查输入文件
if os.path.exists(input_file):
print(f"输入文件大小: {os.path.getsize(input_file) / 1024:.2f} KB")
try:
wb = openpyxl.load_workbook(input_file)
ws = wb.active
print(f"输入文件行数: {ws.max_row}")
print(f"输入文件列数: {ws.max_column}")
except Exception as e:
print(f"读取输入文件出错: {e}")
else:
print("输入文件不存在!")
# 检查输出文件
if os.path.exists(output_file):
print(f"\n输出文件大小: {os.path.getsize(output_file) / 1024:.2f} KB")
try:
wb = openpyxl.load_workbook(output_file)
ws = wb.active
print(f"输出文件行数: {ws.max_row}")
print(f"输出文件列数: {ws.max_column}")
# 显示前10行数据
print("\n前10行数据:")
for row in range(1, min(11, ws.max_row + 1)):
row_data = []
for col in range(1, ws.max_column + 1):
value = ws.cell(row=row, column=col).value
row_data.append(value)
print(f"{row}: {row_data}")
except Exception as e:
print(f"读取输出文件出错: {e}")
else:
print("输出文件不存在!")
print()
print("========================================")
print(" 检查完成")
print("========================================")