I have an HTML form using which user can upload a .xlsx file and calculate pay rates for shifts in .xlsx file(see below)
<form enctype="multipart/form-data" action="/calculate_payrate" method="post">
<label class="label">PLEASE UPLOAD FILE HERE:</label>
<input type="file" id="roaster_file" name="roaster_data"></br>
<input type="submit" id="calculate_input" name="submit" value="CALCULATE PAY" >
</form>
Here is the python code
@view_config(route_name='calculate_payrate',
renderer='../templates/pay/pay.mako')
def calculate_payrate(request):
roaster_data = request.POST['roaster_data']
roaster_data = roaster_data.value
roaster_data = roaster_data.decode('utf-8')
## code to do calculate pay
The problem is - when a user uploads CSV or TSV file, I can get the data in files easily and perform my calculations. But when xlsx file is uploaded and I get below data
FieldStorage('roaster_data', 'abc.xlsx')
b'PK\x03\x04\x14\x00\x06\x00\x08\x00\x00\x00!\x00b\xee\x9dh^\x01\x00\x00\x90\x04\x00\x00\x13\x00\x08\x02[Content_Types].xml and so on...
I am not sure how can I get the data in xlsx file [assuming there is only one sheet in xlsx].
All the questions that I have seen so far about reading data from xlsx require file path and open that file using pandas or some other package. But however I cannot place the file on the Heroku server that I am using and I need to send my file data via the form.
Any pointers are appreciated.
Thanks.