File size: 1,022 Bytes
5beeda0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cdeb89
5beeda0
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
import pandas as pd

def extract_excel_content(file, rows, cols):
    try:
        # 读取上传的Excel文件
        df = pd.read_excel(file, engine='openpyxl')
        
        # 获取特定行数和列数的数据
        extracted_data = df.iloc[:rows, :cols]
        return extracted_data.to_string()
    except Exception as e:
        return f"Error: {str(e)}"

# 创建Gradio界面
with gr.Blocks() as demo:
    gr.Markdown("# Excel内容提取工具")
    gr.Markdown("上传您的Excel文件并指定需要提取的行数和列数")

    file_input = gr.File(label="上传Excel文件")
    row_input = gr.Number(label="行数 (例如 5)", value=5, precision=0)
    col_input = gr.Number(label="列数 (例如 3)", value=3, precision=0)
    output_text = gr.Textbox(label="提取内容")

    extract_button = gr.Button("提取内容")
    
    extract_button.click(fn=extract_excel_content, inputs=[file_input, row_input, col_input], outputs=output_text)

# 运行Gradio应用
demo.launch()