在IronPython中从Excel获取pathstring
我想通过IronPython设置工作目录。 它基本上用于ANSYS Workbench。 我从Excel中获取目录path,我将它存储在一个IronPython中的variables。
dirpath = worksheet.range["E25"].value
我将这个variables值作为AbsUserPathName
和chdir
命令的inputpath。
dir = AbsUserPathName(dirpath) os.chdir(dirpath)
但没有任何工作,它给错误expected str, got _comObject
任何帮助表示赞赏。
假设您使用Microsoft.Office.Interop.Excel您可以使用以下语句之一:
dirpath = worksheet.Range["E25"].Text
要么
dirpath = worksheet.Cells[25, "E"].Text
要么
dirpath = worksheet.Cells[25, 5].Text
你当前的语句暴露了一个来自interop-API的COM对象,甚至可能代表多个单元,因此不能被chdir使用,因为没有办法将范围隐式地转换为string。