从 IronPython 调用 Word.SaveAs 方法
我曾经使用 C# 操作 Word,现在使用 IronPython 进行测试。 这是我的代码:
import clr
clr.AddReference('System')
clr.AddReference('mscorlib')
clr.AddReference('Microsoft.Office.Interop.Word')
from System.Reflection import Missing
from Microsoft.Office.Interop.Word import ApplicationClass
missing = Missing.Value
word = ApplicationClass()
word.Visible = True
doc = word.Documents.Add(missing, missing, missing, missing)
doc_file_name = r"C:\MyWord.docx"
doc.SaveAs(doc_file_name, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
doc.Close(missing, missing, missing)
WordApp.Quit(missing, missing, missing)
SaveAs 调用的 ligne 会导致错误: ValueError: 无法转换参数 0 以调用 SaveAs。
有没有人遇到同样的问题或有解决方案?
I used to manipulate Word from C# and now I test it with IronPython.
Here is my code :
import clr
clr.AddReference('System')
clr.AddReference('mscorlib')
clr.AddReference('Microsoft.Office.Interop.Word')
from System.Reflection import Missing
from Microsoft.Office.Interop.Word import ApplicationClass
missing = Missing.Value
word = ApplicationClass()
word.Visible = True
doc = word.Documents.Add(missing, missing, missing, missing)
doc_file_name = r"C:\MyWord.docx"
doc.SaveAs(doc_file_name, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
doc.Close(missing, missing, missing)
WordApp.Quit(missing, missing, missing)
The ligne with the SaveAs call causes an error : ValueError: Could not convert argument 0 for call to SaveAs.
Did anyone encounter the same problem or have a solution ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于文件类型的值以及您的单词实例是否处于兼容模式。
我做了这些更改并且保存得很好。
这一改变彻底失败了。
I think the problem is with the value of file type and if your instance of word is in compatibility mode or not.
I made these changes and it saved fine.
This change bombed out.