-1

I am trying to read the cell of a excel file in python, change its value and save it. If I do not have the line from xlutils.copy import copy in code, it recognizes workbook.sheeets(), but otherwise it says

    AttributeError: 'Workbook' object has no attribute 'sheets'

Here is my code:

    from xlutils.copy import copy

    import xlrd
    st = xlwt.easyxf('pattern: pattern solid;')
    rb = xlrd.open_workbook('00-17.xlsx')

    workbook = copy(rb)
    for sheet in workbook.sheets():
        for row in range(sheet.nrows):

            current_value = sheet.cell(row,3).value
            if(current_value == '1' ) :
                st.pattern.pattern_fore_colour = 5

                for column in [0,2,3]:
                    value = sheet.cell(row, column).value

                    print value
                    sheet.write(row, column, value,st)
    workbook.save('1.xlsx') 


LightCC
  • 9,804
  • 5
  • 52
  • 92
Pegah
  • 672
  • 2
  • 13
  • 23

1 Answers1

0

I believe you may have to use load_workbook() method first. Check out the link Print Excel workbook using python it will probably help.

Can you try doing it with workbook = xlrd.open_workbook('00-17.xlsx') and remove the line workbook = copy(rb)?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Cary Shindell
  • 1,336
  • 8
  • 25
  • My python has a problem with load_workbook(), and because it does not finde the base package (although I installed it). Could you have a look at my update? – Pegah Jul 07 '17 at 14:28
  • Can you try doing it with `workbook = xlrd.open_workbook('00-17.xlsx')` and remove the line `workbook = copy(rb)`? – Cary Shindell Jul 07 '17 at 14:35