Python Source node error: Execute failed: object of type ‘NoneType’ has no len()

#1

Hi,
I am trying to create a Python Source node so that I can clear data from an Excel sheet’s range.
The code:
from pandas import DataFrame
import openpyxl as xl

ClearDataRangeInExcel

filename1 =r"C:\Personal\Book1.xlsx"
wb2 = xl.load_workbook(filename1)
ws2 = wb2.active
for row in ws2[‘A1:C3’]:

for cell in row:
cell.value = None

output_table = wb2.save(str(filename1))

if I press „execute script” button inside the node the code runs properly without error message => It runs on Jupyter notebook as well.
But when I try to run on Knime (right click \ Execute) I encounter an error message on Console “Execute failed: object of type ‘NoneType’ has no len()” The node status becomes Error but executes the code well (Clearing data in Excel on the appropriate range )

I suspect the last line but cannot figure out the solution.

Any idea?

Thanks,
Gabor

0 Likes

#2

The last lines could be something like this:

import pandas as pd

wb2.save(str(filename1))
output_table = pd.DataFrame(wb2.values)

The save command cannot be interpreted as a data frame. If you do not need the data frame back you could opt for something like this where you just give back the name of the file (eg.):

wb2.save(str(filename1))
output_table = pd.DataFrame( 
                { "my_excel_file" : [filename1] 
                    } 
                ) 
2 Likes

#3

Thank you, it works now!

2 Likes

closed #4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

0 Likes