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

Guys,

Suppose I have a binary filed to upload xls file.

data = fields.Binary()

My requirement is I want to get the values of xls in a python function as a Two dimensional list.

[  [row1], [row2], [row3], [row4],.... ]

Is this possible  ... ?

or another way ?

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

 Use xlrd to read the file as given below. I have done it in odoo9. You may try this.

from xlrd import open_workbook
import base64

def read_excel(self):
    wb = open_workbook(file_contents = base64.decodestring(obj.data))
    sheet = wb.sheets()[0]

    for s in wb.sheets():

         values = []

         for row in range(s.nrows):

             col_value = []

             for col in range(s.ncols):

                 value  = (s.cell(row,col).value)

                 try : value = str(int(value))

                 except : pass

                 col_value.append(value)

             values.append(col_value)

     print values

อวตาร
ละทิ้ง
ผู้เขียน

Excellent !!!

Thank u Sebin, This is what I expected .

You are welcome Shameem.

obj should be your object in which you are using the binary field to save the xls file

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 25
4625
2
ธ.ค. 24
7773
How to ORDER BY? [Odoo 10] แก้ไขแล้ว
2
พ.ย. 24
28540
2
พ.ค. 24
7481
3
มี.ค. 24
6913