SelenaNovelis commited on
Commit
814a8c7
1 Parent(s): 6c820f0
Files changed (2) hide show
  1. app.py +42 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openpyxl
3
+ from io import BytesIO
4
+ import tempfile
5
+
6
+ st.title("💹 改变表格中数值单位")
7
+
8
+ with st.expander("💡 使用介绍"):
9
+ st.info("首先上传 xlsx 或者 csv 文件,然后选择文件中需要调整单位的表格,输入更改后的单位。例如:万元 输入 10000。最后点击下载。")
10
+ st.info("注意:这里默认原上传文件单位为元,如果原上传单位为万元,需要调整到元,则在‘更改后单位值’输入 0.0001。")
11
+
12
+ uploaded_file = st.file_uploader("1. 上传表格文件", type=["csv","xlsx"])
13
+
14
+ if uploaded_file is not None:
15
+ wb = openpyxl.load_workbook(uploaded_file)
16
+
17
+ container = st.container()
18
+ all = st.checkbox("选择所有")
19
+
20
+ if all:
21
+ selected_options = container.multiselect("2. 选择一个或者多个表格:",
22
+ wb.sheetnames,wb.sheetnames)
23
+ else:
24
+ selected_options = container.multiselect("2. 选择一个或者多个表格:",
25
+ wb.sheetnames)
26
+
27
+ d = st.text_input("3. 更改后单位值")
28
+
29
+ if len(selected_options) != 0 and d != '':
30
+ for i in selected_options:
31
+ ws = wb[i]
32
+ for row in ws.iter_rows():
33
+ for cell in row:
34
+ if cell.data_type == 'n':
35
+ if cell.value != None:
36
+ cell.value = cell.value/int(d)
37
+
38
+ with tempfile.NamedTemporaryFile() as tmp:
39
+ wb.save(tmp.name)
40
+ data = BytesIO(tmp.read())
41
+
42
+ st.download_button(label='📥 下载结果文件', data=data, mime='xlsx', file_name= uploaded_file.name)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ openpyxl
3
+ BytesIO
4
+ tempfile
5
+