Can you please help on my below code , i am trying to read excel file by uploading it from local and then i need to choose sheetname , based on my sheetname i need to parse the excel and do some other logic .I am struck at selecting sheetname .After i choose sheetname i m not able to pass it to df reader can someone help
if page =="excel":
st.subheader("Dataset")
data_file = st.file_uploader("Upload excel",type=['xlsx'])
if st.button("Process"):
if data_file is not None:
file_details = {"Filename":data_file.name,"FileType":data_file.type,"FileSize":data_file.size}
st.write(file_details)
wb = openpyxl.load_workbook(data_file)
sidebar = st.sidebar
sheet_selector = sidebar.selectbox("Select sheetname",wb.sheetnames)
st.markdown(f"# Currently Selected {sheet_selector}")
df = pd.read_excel(data_file,sheet_selector)
st.header("Sheet view")
data_file = st.sidebar.file_uploader("Upload Excel file",type=['xlsx'])
if data_file:
file_details = {
"Filename":data_file.name,
"FileType":data_file.type,
"FileSize":data_file.size}
wb = openpyxl.load_workbook(data_file)
## Show Excel file
st.sidebar.subheader("File details:")
st.sidebar.json(file_details,expanded=False)
st.sidebar.markdown("----")
## Select sheet
sheet_selector = st.sidebar.selectbox("Select sheet:",wb.sheetnames)
df = pd.read_excel(data_file,sheet_selector)
st.markdown(f"### Currently Selected: `{sheet_selector}`")
st.write(df)
## Do something after a button
doLogic_btn = st.button("➕")
if doLogic_btn:
df2 = df.sum().transpose()
st.write(df2)
# Do something more after the previous button
# >> But this will fail because the button will go back to _False_
# >> so nothing will be shown afterwards
another_btn = st.checkbox("Another +")
if another_btn:
df3 = df2.sum()
st.write(df3)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.