I want to user upload excel file by "fields.Binary()";
when the user click a certain button, this excel file will be downloaded on server; and then use "xlrd.open_workbook(filename[0])" to get the excel data and do the next doings;
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I want to user upload excel file by "fields.Binary()";
when the user click a certain button, this excel file will be downloaded on server; and then use "xlrd.open_workbook(filename[0])" to get the excel data and do the next doings;
Hello,
Odoo already have method for download file from binary data.
@http.route('/web/binary/saveas', type='http', auth="public")
@serialize_exception
def saveas(self, model, field, id=None, filename_field=None, **kw):
-------
-------
This method available on '/web/controllers/main.py'
You can use this method by pass parameter in url.
Example:
URL : localhost:8069/web/binary/saveas?model=ir.attachment&field=datas&filename_field=datas_fname&id=103
Using this url odoo will give you data of field datas from ir.attachment model of record id is 103.
------------------------- Code is For reading Excel file that store in Binary format--------------------------
import base64
from openerp import api, fields, models, _
from openpyxl import load_workbook
class ExcelRead(models.TransientModel):
_name = "excel.read"
data_file=fields.Binary('File')
@api.one
def import_file(self):
data_file_p = open('/tmp/test.xlsx','w')
data_file_p.write((base64.b64decode(self.data_file)))
data_file_p.close()
wb = load_workbook('test.xlsx')
ws = wb['big_data']
for row in ws.rows:
for cell in row:
print(cell.value)
Hope this helps.
Thanks for your reply;
In the fact I want to get the data from the uploaded excel file of "fields.Binary()";
the code:
.....
filedata=fields.Binary();
...
Now I have uploaded an excel file to "filedata";
My question: how shall I get the the first column data of the Excel file from "filedata"?
is that file type of csv ?
Here i have update my answer and add code for read excel file that store in Binary format.
Thank you very much, Antala,
your reply resolves my problems absolutely.
Thanks for your time, your efforts and your patience.
Now I have import excel data from user's terminal and shall I write the modified data back to user's terminal as excel file?
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jul 16
|
13754 | ||
|
3
Aug 24
|
395 | ||
|
2
May 24
|
578 | ||
|
1
Mar 19
|
3420 | ||
|
2
Mar 17
|
3786 |
You can get an idea from here: http://learnopenerp.blogspot.com/2020/06/write-binary-data-nto-zip-file-and-downlaod-it-on-button-click-in-odoo.html