如下图,AI指令输出的代码并没有改变excel单元格中内容的颜色

附上AI生成的代码:
# 使用此指令前,先安装必要的python库,使用以下命令
# pip install pandas
# pip install openpyxl
# pip install xlrd
import pandas as pd
from typing import *
from xbot importprint
defcompare_and_write_table(table: str, column1: str, column2: str) -> str:
"""
title: 比较表格列内容并将增减的内容写入表格中
description: 依次比较表格中从第1行到第n行,同行某两列的内容,将增减的内容写入在本表格中该行的“变化内容”一列,只写入当前不一致的项,以换行符为结尾。形式为:增加:增加的内容(用红色标注),或者减少:减少的内容(用蓝色标注),全部写入后保存表格。
inputs:
- table (file): 表格文件的路径,支持csv、excel等常见格式
- column1 (str): 第一列的列名
- column2 (str): 第二列的列名
outputs:
- compared_table (file): 比较后的表格文件,增减的内容写入在表格中该行的“变化内容”一列
"""
df = pd.read_csv(table) if table.endswith('.csv') else pd.read_excel(table)
compared_table = df.copy()
for i inrange(len(df)):
items1 = str(df.loc[i, column1]).split('\n')
items2 = str(df.loc[i, column2]).split('\n')
added_items = [f"增加:{item}"for item in items1 if item notin items2]
removed_items = [f"减少:{item}"for item in items2 if item notin items1]
change_content = ""
if added_items:
change_content += "<span style='color: red;'>" + "<br>".join(added_items) + "</span>"
if removed_items:
change_content += "<span style='color: blue;'>" + "<br>".join(removed_items) + "</span>"
compared_table.loc[i, '变化内容'] = change_content
if table.endswith('.csv'):
compared_table.to_csv(table, index=False)
else:
compared_table.to_excel(table, index=False, engine='openpyxl')
return"表格已成功保存"