Joe
Joe

Reputation: 395

Cannot convert to Excel in Python 3.X, however works in Python 2.X

In the code snippet below, I am trying to open and excel worksheet in Python and then carryout some calculations. The code works with Python 2.X, but I am having problems with the Python 3.0 implementation. While trying to run the code, I get the error ValueError: Cannot convert <Cell 'Sheet1'.A1> to Excel

Can you tell me how to fix this code to work with Python 3.6

Here is the code that I have so far:

import openpyxl
from openpyxl import load_workbook
import os
# import pandas as pd
import xlwings as xw


os.chdir("C:/Users/boss/Desktop/for_Interns/Code")

wb= openpyxl.load_workbook("F2_copy.xlsx")
wb.create_sheet(index=0,title='Summary')
sumsheet= wb.get_sheet_by_name('Summary')
print('Creating Summary Sheet')
for sheet in wb.worksheets:
    for row in  sheet.iter_rows():
        for cell in row:
           if cell.value=='failed':

               my_values= xw.Range('14_Messsage','A1:A6').options(ndim=2).value
               xw.Range('Summary','A1:A6').value = my_values

#loop through worksheets
print("Looping Worksheets")
for sheet in wb.worksheets:
    for row in  sheet.iter_rows():
        for cell.value in row:
           if cell.value=='LowLimit':
                lowCol=cell.column
            if cell.value=='HighLimit':
                highCol=cell.column
            if cell.value=='MeasValue':
                measCol=cell.column
       ....

Upvotes: 0

Views: 886

Answers (1)

Xukrao
Xukrao

Reputation: 8634

Try replacing the line

for cell.value in row:

with

for cell in row:

Upvotes: 1

Related Questions