This is the project to compare two excel sheets and generate another excel file called Excel_diff.xlsx to show the difference.
I have written the following script and I wish to set the width of Column A to 30 using a function called properties()
.
The code can be compiled without any error. However, the output Excel_diff.xlsx does not have the width of 30 in Column A. May I ask which part of my script is written wrongly and how to change it to achieve the objective?
My approach is to use worksheet.set_column(1,1,30)
to set the width of starting and ending of the column desired (column A) to 30.
Thank you.
import pandas as pd
import numpy as np
import xlsxwriter as xw
def comparison():
df1=pd.read_excel('Testing.xlsx', 'Sheet1')
df2=pd.read_excel('Testing.xlsx', 'Sheet2')
comparison_values = df1.values == df2.values
rows,cols=np.where(comparison_values==False)
for item in zip(rows,cols):
df1.iloc[item[0], item[1]] = '{} --> {}'.format(df1.iloc[item[0], item[1]],df2.iloc[item[0], item[1]])
df1.to_excel('./Excel_diff.xlsx',index=False,header=True)
def properties():
workbook=xw.Workbook('./Excel_diff.xlsx')
worksheet=workbook.add_worksheet()
worksheet.set_column(1,1,30)
properties()
comparison()