python中调用win32com启动dll文件,报错
答案:2 悬赏:30 手机版
解决时间 2021-03-02 12:52
- 提问者网友:听门外雪花风
- 2021-03-02 06:48
错误:pywintypes.com_error: (-2147024770, '\xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\xa3', None, None)
最佳答案
- 五星知识达人网友:英雄的欲望
- 2021-03-02 08:01
'\xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\xa3'.decode('gbk')
'找不到指定的模块。'
'找不到指定的模块。'
全部回答
- 1楼网友:轻熟杀无赦
- 2021-03-02 08:35
import sys, time, string, win32com.client, stat, os
class cwordautomate:
"""封装word com 连接"""
def __init__( self ):
"""创建到word的ole连接对象"""
self.m_obword = win32com.client.dispatch( "word.application" )
self.m_obdoc = self.m_obword.documents.add( ) #创建文档
self.m_obword.visible = 1
self.m_sel = self.m_obword.selection # 获取选择对象
def writeline( self, stxt, sfont, lsize, bbold=0 ):
"""写一行到文档"""
self.m_sel.font.name = sfont
self.m_sel.font.bold = bbold
self.m_sel.font.size = lsize
self.m_sel.typetext( text=stxt + "\n" )
def save(self, sfilename):
self.m_obdoc.saveas(sfilename)
def quit(self):
self.m_obword.quit()
def file_test(file):
"""
测试用户提供的文件,查看它是否存在并包含数据。
如果输入文件不存在或是空的,则返回一个警告代码
"""
if (0 == os.path.isfile(file) or (0 == os.stat(file)[stat.st_size])):
return 1
else:
return 0
if __name__ == "__main__":
usage = "\n\n\tusage: msword.py {inputfile} {outputfile}\n"
#
# 测试传入数字的参数
#
if len(sys.argv) != 3:
print "\n\n\tmsword.py error: \n\n\tinsufficient arguments passed."
print usage
sys.exit(1)
# 测试源文件是否存在并包含数据
if file_test(sys.argv[1]) == 1 :
print "\n\n\tmsword.py error: \n\n\tsource file not found or is empty."
print usage
sys.exit(1)
# 测试目标文件,避免意外导致崩溃
if file_test(sys.argv[2]) == 0 :
print "\n\n\tmsword.py error: \n\n\ttarget file already exists."
print usage
sys.exit(1)
sfilename = sys.argv[1]
obfile = file( sfilename, 'r+' )
scontent = obfile.read()
obfile.close()
lstcontent = scontent.splitlines()
#
# 写入数据
#
obword = cwordautomate()
for sline in lstcontent:
obword.writeline( sline, "courier new", 10 )
slastmsg = time.strftime( "document generated on %c", time.localtime() )
obword.writeline( slastmsg, "times new roman", 14, 0 )
obword.save(sys.argv[2])
obword.quit()
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯