is there any way to fix this error?
AnvilWrappedError: [Errno 2] No such file or directory: ‘list.xlsx’
is there any way to fix this error?
AnvilWrappedError: [Errno 2] No such file or directory: ‘list.xlsx’
So here are the python code and anvil code, im trying to convert an excel file to the other excel file format.
when I upload a file, and an error pops up
[AnvilWrappedError: [Errno 2] No such file or directory: ‘list.xlsx’]
Jupyter:
import anvil.media
from openpyxl import load_workbook
@anvil.server.callable
def convert_file(file):
wb =load_workbook(file, read_only= False, keep_vba=True)
fname1 = file.strip(".xlsx")
fname1 = fname1 + “.xlsm”
wb.save(fname1)
Anvil code:
def file_loader_change(self, file, **event_args):
filename= file.name
result = anvil.server.call(“convert_file”,filename)
print(‘File has been converted successfully’)
Hi @pananya21t, welcome to the forum!
Thanks for providing the code sample - that makes the problem a little more obvious. (Tip: you can use ```python
blocks to format your code – check out the how to ask a good question post for details)
The FileLoader component is giving you a Media object - but all you’re sending to the server is the filename. Instead, if you send the file
object to the server, you will transmit the uploaded file to your Jupyter notebook.
Now you need to get it into openpyxl
. The load_workbook()
function is expecting to load its data from a file, so you need to write that data to a temporary file, using anvil.media.TempFile
. You’ll want to do something like
with anvil.media.TempFile(file) as filename:
wb = load_workbook(filename, read_only=False, keep_vba=True)
Does that make sense?
Using anvil.media.TempFile, I’m the getting this error as openpyxl doesn’t support the file format.
InvalidFileException: openpyxl does not support file format, please check you can open it with Excel first. Supported formats are: .xlsx,.xlsm,.xltx,.xltm.
Also having this problem.
‘’‘’
def Reporttoreview(reporttoreview, previousreport):
with anvil.media.TempFile(reporttoreview) as f:
print(f)
wb = load_workbook(f, read_only = False, keep_vba = True, data_only=True)
'Get the information from the current cover page'
ws = wb.get_sheet_by_name('Cover')'''
You are unlikely to get an answer when you revive old defunct posts.
Please create a new post, show the failing code, the error message and highlight the failing line, and ask a question.
When you put some code on a post, you can format it with one line with ```
before and one after.