【Python百日进阶-Web开发-Feffery】Day603 - 趣味dash_03:读取Excel文件

一、环境准备

1.1 初始化基础Python + Dash环境

CSDN文档参见:https://blog.csdn.net/yuetaope/article/details/129795264
Bilibili视频参见:https://www.bilibili.com/video/BV1Xc411V7Cp

1.2 本例中使用的第三方包

二、本项目B站视频讲解

https://www.bilibili.com/video/BV1aM411M7xe

三、页面效果

在这里插入图片描述

四、项目源码

# -*- coding: utf-8 -*-
# @Time    : 2023/3/28 18:29
# @Author  : 岳涛
# @File    : main.py
# @Des     :
import dash
import pandas as pd
from dash import html, Input, Output
import feffery_antd_components as fac

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        html.H1('趣味dash_03:读取Excel文件'),
        fac.AntdButton('读取Excel文件', id='btn_read_excel'),
        html.Hr(),
        html.Div(id='content')
    ]
)


@app.callback(
    Output('content', 'children'),
    Input('btn_read_excel', 'nClicks'),
)
def function(nClicks):
    if nClicks:
        df = read_xlsx()
        return fac.AntdTable(
            data=df.to_dict('records'),
            columns=[{
                'title': c,
                'dataIndex': c,
                'editable': c in ['规格', '数量'],
                'renderOptions': {'renderType': 'copyable'} if c in ['规格'] else {},
            } for c in df.columns],
            sortOptions={
                'multiple': 'auto',
                'sortDataIndexes': df.columns,
            },
            filterOptions={
                i: {'filterMultiple': True} for i in df.columns
            },
            pagination={
                'pageSize': 10,
                'current': 5,
                'pageSizeOptions': [5, 10, 15, 20, 25],
                'showTotalPrefix': '本次共取得示例数据 ',
                'showTotalSuffix': ' 条!😋'
            }
        )
    return dash.no_update


def read_xlsx():
    df = pd.read_excel('卫生明细查询.xlsx')
    df.fillna('', inplace=True)
    return df


if __name__ == '__main__':
    app.run_server(debug=True)


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

岳涛@心馨电脑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值