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.
لقد تم الإبلاغ عن هذا السؤال
2
الردود
6613
أدوات العرض
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
فبراير 21
|
3868 | ||
|
|
3
نوفمبر 20
|
7009 | ||
|
|
1
يوليو 20
|
18764 | ||
|
|
1
يناير 21
|
5173 | ||
|
|
2
أكتوبر 24
|
6088 |