I am new to Django and I have a Django application where once you upload few excel files, it does a background calculation and saves the results in an excel file. I need to show those excel files with minimal processing in the Django home page as datatable. I tried django-excel package with Iframe to do so. I am not not able to get the page. Please suggest if the code below needs to be modified. Is there any other ways to solve this problem?
In views.py:
import django_excel as excel
import pyexcel as p
def show_result_files(request,foldername,outputfilenames):
file_path = path + '/Data/' + foldername
if os.path.isfile(file_path + 'Final_Results.xlsx'):
for afile in request.FILES.getlist(outputfilenames):
combined_sheet = p.get_sheet(file_path + '2020MY EWPR Combined Parts List Final.xlsx')
combined_sheet.save_as(afile.sortable.html)
from IPython.display import IFrame
IFrame("afile.sortable.html", width=600, height=500)
In home.html:
<div class="inline col-md-9" id="showFinalResults">
<form method="POST" name="showCombined" action="">{% csrf_token %}
<button name="showCombined" type="submit" class="btn btn-primary">Combined Parts List</button>
</form>
</div>
<div class="inline col-md-9" id="showFinalResults">
<form method="POST" name="showCombined" enctype="multipart/form-data" action=''>{% csrf_token %}
<div class="col">
<div class="row">
<span class="btn btn-primary btn-file">
Combined Parts List <input name="SparrowFiles" id="Sparrow" type="file" multiple="">
</span>
<button name='upload_Sparrow' type="submit" class="btn btn-secondary js-upload-files" data-toggle="modal" data-target="#modal-progress_sp"">Go</button>
</div>
</div>
</form>
</div>
What I want the resulting excel file displayed in the Home page when a "showCombined" button is clicked
There are various options, depending on whether you want the spreadsheet data to be accessiblew to users who cannot use excel, or not.
The most general is for the button to be a hyperlink that invokes a Django view which renders the spreadsheet data as an HTML
<table>. There is a completely awesome JavaScript called DataTables that can make such a table almost as functional as Excel insofar as display is concerned. Very easy to use: start simple, then add tweaks until perfected. Absolutely loads of examples available (and much support with it on StackOverflow).Another is for the computation which saves its results as Excel to also save as pdf alongside, and to serve up the pdf in that hyperlink.
Finally, you can make the target of the link the xlsx file itself, and the user's browser will ask how to open it if Excel is not already set up as default (which it probably will be, on a Windows box. On a Linux box LibreOffice Calc will probably accomplish much the same.).