I am trying to use xlwings to read excel file, my code is working locally but it’s throwing error : ‘nonetype’ object has no attribute ‘apps’ when running in cloud.
I have already tried openpyxl and it’s working in cloud but i really hate it’s api and it’s missing some functinality
here is my sample code
import streamlit as st
import xlwings as xw
import os
st.title("Excel File Reader")
# File uploader
uploaded_file = st.file_uploader(
"Choose an Excel file", type=['xlsx', 'xls'])
if uploaded_file is not None:
# Save the uploaded file temporarily
with open("temp.xlsx", "wb") as f:
f.write(uploaded_file.getbuffer())
try:
# Open the Excel file
app = xw.App(visible=False)
wb = app.books.open("temp.xlsx")
sheet = wb.sheets[0] # Get first sheet
# Read cell B1
cell_value = sheet.range("B1").value
# Display the value
st.write(f"Value in cell B1: {cell_value}")
st.write(sheet.range("Area").value)
st.write(sheet.range("B4:E7").value)
# Clean up
wb.close()
app.quit()
os.remove("temp.xlsx")
except Exception as e:
st.error(f"An error occurred: {str(e)}")
# Clean up in case of error
if 'wb' in locals():
wb.close()
if 'app' in locals():
app.quit()
if os.path.exists("temp.xlsx"):
os.remove("temp.xlsx")