Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4587 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
  1. 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



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi you can check this: 


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 21
2541
3
thg 11 20
4916
1
thg 7 20
15910
1
thg 1 21
3281
2
thg 10 24
3721