I want to the user to upload an excel file using an HTML form (input type="file") and then process it in a controller and make records based on its rows. how can I achieve it? Thanks in advance.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
2
回复
4452
查看
I've figured it out myself.
xml:
<form class="o_form_binary_form" method="POST" enctype="multipart/form-data" action="/my/order/excel/uploaded">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<label class="control-label" for="file">File:</label>
<input accept="xls, .xlsx" class="o_input_file" type="file" name="file"/>
<button type="submit" class="btn btn-primary pull-left">Submit</button>
</form>
python controller:
from xlrd import open_workbook
@http.route(['/my/order/excel/uploaded'], type='http', auth="user", website=True)
def portal_create_order_excel(self, file):
excel_data = file.read()
book = open_workbook(file_contents=excel_data)
sheet = book.sheets()[0]
for i in range(sheet.nrows):
// do what you do
// do what you do
Hi you can check this:
相关帖文 | 回复 | 查看 | 活动 | |
---|---|---|---|---|
|
0
2月 21
|
2459 | ||
|
3
11月 20
|
4836 | ||
|
1
7月 20
|
15751 | ||
|
1
1月 21
|
3190 | ||
|
2
10月 24
|
3563 |