我正在使用Python脚本格式化大量Excel 2010文档。 Python脚本正在使用Win32Com和Pandas。现在,我已经两次尝试格式化不存在的文件。发生这种情况时,Python返回以下错误/通知:
Reloaded modules: win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7, win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7._Application, win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7.Workbooks, win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7.Workbook, win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7.WorkbookEvents, win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7._Workbook, win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7.Application, win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x7.AppEvents
这是一个非常糟糕的错误吗?它是否影响Windows的系统文件?
我尝试重新启动Python,Spyder和我的计算机。另外,我确保文件存在。
import win32com.client as win32
import pandas
jobRequested = input("What property tax job would you like to format? ")
fileName = "\\" + jobRequested
stateCode = "\\" + fileName[1:3]
fname = "\\\\path\\is\\redacted\\here" + stateCode + fileName + "\\Export.xls"
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(fname)
# Convert .xls to .xlsx
wb.SaveAs(fname+"x", FileFormat = 51)
wb.Close()
excel.Application.Quit()
# Sets the export path based on the input
jobPath = ("\\\\path\\is\\redacted\\here" + stateCode + fileName)
exportFilePath = "\\\\path\\is\\redacted\\here" + stateCode + fileName + "\\Export.xlsx"
# Exports the data to an output file
dataframe = pandas.read_excel(exportFilePath, parse_cols = [0, 1, 4, 6])
dataframe = dataframe.sort_values(by="Name")
dataframe.to_excel(jobPath + "\\output.xlsx")
我希望Python脚本可以格式化Excel文件。
由于Win32软件包已经重新加载,我想知道是否需要重新加载它们会造成任何类型的损坏。