filename = DSTRESSTOOLGPU_Caps_Viewerbenchmark2xlsxxlApp = DispatchExcelApplicationxlAppVisible = True # 显式打开excel 调试设置Truebook = xlAppWorkbooksAddxlSheet = bookWorksheets1xlSheetCells1 1Value = Benc
这个错误可能是由于找不到指定的图片文件而导致的。请确保指定的图片文件路径是正确的,并且文件存在。如果文件路径是正确的,可以尝试使用绝对路径来替代相对路径。另外,还可以尝试使用其他方法来插入图片,例如使用AddPicture方法。以下是修改后的代码示例:
import win32com.client as win32
filename = "D:\\STRESSTOOL\\GPU_Caps_Viewer\\benchmark\\2.xlsx"
xlApp = win32.Dispatch('Excel.Application')
xlApp.Visible = True
book = xlApp.Workbooks.Add()
xlSheet = book.Worksheets(1)
xlSheet.Cells(1, 1).Value = 'Benchmark Tool'
xlSheet.Cells(2, 1).Value = 123
shape = xlSheet.Shapes.AddPicture("D:\\STRESSTOOL\\GPU_Caps_Viewer\\benchmark\\1.png", False, True, Left=xlSheet.Cells(8, 7).Left, Top=xlSheet.Cells(2, 2).Top, Width=shape.Width, Height=shape.Height)
xlSheet.Rows(2).RowHeight = shape.Height
xlSheet.Columns(2).ColumnWidth = shape.Width
book.SaveAs(filename)
请根据你的实际需求进行适当调整
原文地址: http://www.cveoy.top/t/topic/iJmn 著作权归作者所有。请勿转载和采集!