Untitled

 avatar
unknown
plain_text
5 months ago
674 B
2
Indexable
import os
import sys
import pandas as pd

def resource_path(relative_path):
    """Lấy đường dẫn file trong thư mục tạm hoặc thư mục gốc"""
    try:
        # PyInstaller tạo file .exe sẽ có sys._MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        # Khi chạy trong môi trường phát triển (script Python), dùng thư mục hiện tại
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)

# Đường dẫn đến file Excel
file_path = resource_path('example.xlsx')

# Đọc file Excel
df = pd.read_excel(file_path, engine='openpyxl')

# Hiển thị nội dung DataFrame
print(df)
Editor is loading...
Leave a Comment