Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4622 มุมมอง

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.

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด
  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



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi you can check this: 


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 21
2546
3
พ.ย. 20
4927
1
ก.ค. 20
15941
1
ม.ค. 21
3293
2
ต.ค. 24
3739