parser library exportar best django excel xlrd

library - Django y xlrd, leyendo de memoria



xlrd documentation (1)

if form.is_valid(): input_excel = request.FILES[''input_excel''] book = xlrd.open_workbook(file_contents=input_excel.read()) # your work with workbook ''book'' return render_to_response(''import_excel.html'', {''rows'': rows})

Cuando se proporciona la palabra clave opcional file_contents , no se usará la palabra clave filename .

Feliz Codificación.

Mi plan es permitir que un usuario cargue un archivo de Excel. Una vez cargado, mostraré un formulario editable que contiene el contenido del Excel cargado, una vez que el usuario confirme que la entrada es correcta, presionará el botón Guardar y estos elementos se guardarán. en algún modelo.

Para esto, he escrito esta vista y forma:

formar:

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

ver:

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})

Como puede ver en el # I need to open this input_excel with input_excel.open_workbook() Necesito leer desde la memoria pero open_workbook lee desde un archivo, sin guardar esta entrada en algún lugar, ¿cómo puedo leerla?