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.

55 lines
1.7 KiB

import flet as ft
import pandas as pd
import requests
from requests.auth import HTTPBasicAuth
from globalState import AppState
def upload(page: ft.Page):
user = AppState.user
password = AppState.password
url = AppState.url
page.title = "Seleccionar archivo y cargar en variable"
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.vertical_alignment = ft.CrossAxisAlignment.CENTER
text = ft.Text(
"¡Nota importante!",
style=ft.TextStyle(
size=30,
font_family="Roboto",
weight=ft.FontWeight.BOLD,
)
)
text2 = ft.Text("El archivo debe estar en formato de excel(xlsx)")
file_picker = ft.FilePicker(
on_result=lambda f: process_file(f)
)
page.overlay.append(file_picker)
def select_file(e):
file_picker.pick_files(
allowed_extensions=["xlsx"],
allow_multiple=True
)
def process_file(file):
if file:
for f in file.files:
if f.name.endswith('.csv'):
df = pd.read_csv(f.path)
print(f"Datos de {f.name}:\n", df.head())
elif f.name.endswith('.xlsx'):
sheets = pd.read_excel(f.path, sheet_name=None)
for sheet_name, df in sheets.items():
print(f"Datos de {sheet_name} en {f.name}:\n", df.head(), "\n")
upload_button = ft.ElevatedButton(text="Seleccionar archivo", on_click=select_file)
container = ft.Container(
content=upload_button,
)
container.margin = ft.margin.only(top=20)
page.add(text, text2)
page.add(container)