Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango and xlrd, reading from memory
    primarykey
    data
    text
    <p>My plan is to let a user to upload an excel file, once uploaded I will be displaying editable form which contains the content of the uploaded excel, once user confirms the input is correct, he/she hits the save button and these items are saved at some model.</p> <p>For this, I have written this view and form:</p> <p><strong>form:</strong></p> <pre><code>IMPORT_FILE_TYPES = ['.xls', ] class XlsInputForm(forms.Form): input_excel = forms.FileField(required= True, label= u"Upload the Excel file to import to the system.") def clean_input_excel(self): input_excel = self.cleaned_data['input_excel'] extension = os.path.splitext( input_excel.name )[1] if not (extension in IMPORT_FILE_TYPES): raise forms.ValidationError( u'%s is not a valid excel file. Please make sure your input file is an excel file (Excel 2007 is NOT supported.' % extension ) else: return input_excel </code></pre> <p><strong>view:</strong></p> <pre><code>def import_excel_view(request): if request.method == 'POST': form = XlsInputForm(request.POST, request.FILES) if form.is_valid(): input_excel = request.FILES['input_excel'] # I need to open this input_excel with input_excel.open_workbook() return render_to_response('import_excel.html', {'rows': rows}) else: form = XlsInputForm() return render_to_response('import_excel.html', {'form': form}) </code></pre> <p>As you can see at the <code># I need to open this input_excel with input_excel.open_workbook()</code> I need to read from memory but <code>open_workbook</code> reads from a file, without saving this input to somewhere, how can I read it ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload