콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
4621 화면

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: 


아바타
취소
관련 게시물 답글 화면 활동
0
2월 21
2546
3
11월 20
4927
1
7월 20
15940
1
1월 21
3293
2
10월 24
3739