【问题标题】:how to fetch the data of each excel row into html templates?如何将每个excel行的数据提取到html模板中?
【发布时间】:2020-09-28 02:39:59
【问题描述】:

我需要在 Django 中上传一个 excel 文件。然后我想从 excel 的每一行中获取某些值并将其粘贴到 html 模板中。 需要重复此过程,直到整个 excel 行完成。

【问题讨论】:

    标签: python html django excel templates


    【解决方案1】:

    您可以使用 Pandas 并通过单独的视图 (AJAX) 将它们插入 div 元素。

    pip install pandas 
    

    注意:假设您要阅读后端,则答案适用

    import pandas as pd
    
    # If you're new to python help yourself - https://pandas.pydata.org/
    
    df = pd.DataFrame(columns=list('ABCD'))
    
    for i in range(0,5):
        df.loc[i] = [i, i+1, i+2, i*i]
        
    print(df)
    
    print(df.to_html())
    

    【讨论】:

    • 如前所述,我想从 Excel 工作表中导入数据。
    猜你喜欢
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    相关资源
    最近更新 更多