我得到了一个看起来有问题的错误。因为当然 worksheet 对象有 set_column() 作为函数,它在文档中有说明。我可能做了一些愚蠢的事情,比如掉了一个括号。
这里是错误信息:
Traceback (most recent call last):
File "scrubaddresses.py", line 137, in <module>
run()
File "scrubaddresses.py", line 118, in run
format_col_width(worksheet)
File "scrubaddresses.py", line 24, in auto_format_cell_width
ws.set_column('B:C', 20)
AttributeError: 'Worksheet' object has no attribute 'set_column'
这是我荒谬的导入。 Config 是一些常量,控制器有一些帮助函数。
from smartystreets_python_sdk import StaticCredentials, exceptions, Batch, ClientBuilder
from smartystreets_python_sdk.us_street import Lookup as StreetLookup
from pathlib import Path
import pandas as pd
import numpy as np
import config
from controller import getExcel, clean
所涉及的函数:
def format_col_width(ws):
ws.set_column('B:C', 20)
ws.set_column('D', 1)
ws.set_column('E', 20)
传递ws的源头:
df1 = df.replace(np.nan, '', regex=True)
print(df1)
df1.to_excel(writer, sheet, index = False, engine='xlsxwriter')
worksheet = writer.sheets[sheet]
format_col_width(worksheet)
我是不是忘记导入什么东西了?Xlsxwriter已经安装。