Is Python.xlsx reader (Office OpenXML) as simple as csv module?

I know that some Python xlsx readers appear, but from what I saw, they don't seem almost intuitive, like a built-in module csv.

I want a module that can do something like this:

reader = xlsx.reader(open('/path/to/file'))

for sheet in reader:
    print 'In %s we have the following employees:' % (sheet.name)
    for row in sheet:
        print '%s, %s years old' % (row['Employee'], row['Age'])

Is there such a reader?

+3
source share
2 answers

xlrd has xlsx processing to extract the main data using the same APIs as xls in the alpha test at the moment. Send me a personal email if interested.

+4
source

Well, maybe not for xlsx format, but for xls. Grab xlrd from here:

http://www.python-excel.org/

, , :

import xlrd

EMPLOYEE_CELL = 5
AGE_CELL = 6

reader = xlrd.open_workbook('C:\\path\\to\\excel_file.xls')
for sheet in reader.sheets():
    print 'In %s we have the following employees:' % (sheet.name)
    for r in xrange(sheet.nrows):
        row_cells = sheet.row(r)
        print '%s, %s years old' % (row_cells[EMPLOYEE_CELL].value, row_cells[AGE_CELL].value)

xls, . , , 100% . .

EDIT:

, . - PyODConverter xlsx xls, . - :

user@server:~# python DocumentConverter.py excel_file.xlxs excel_file.xls user@server:~# python script_with_code_above.py

, , , , .

+2

Source: https://habr.com/ru/post/1753394/


All Articles