Mirosoft Office自动化问题

我们习惯于将Jenkins slave安装成Windows Service,而微软的Office自动化部分,不支持以Windows Service的方式运行。以下的代码,如果在Jenkins Slave ( As windows service) 中运行,将导致Word打开的时候出错。( doc = word.Documents.Open(in_file) )

import sys
import os
import time
import win32com.client

wdFormatPDF = 17

in_file = r'C:\Users\Administrator\Desktop\Build\ter\forExample.doc'

word = win32com.client.Dispatch('Word.Application')

word.Visible = True
word.ScreenUpdating = False
    
in_file = os.path.join(docDir, doc['docName'])
out_file = in_file.split('.')[0] + '.pdf'

doc = word.Documents.Open(in_file)
time.sleep(15)

doc.Activate()
doc.AcceptAllRevisions()
doc.Revisions.AcceptAll()
if (doc.Comments.Count != 0):
    doc.DeleteAllComments()
    
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()

word.Quit()


解决的办法是:

1. Create a desktop folder for the system profile, as:

 C:\Windows\System32\config\systemprofile\Desktop

and, if running on a 64-bit machine, create another one, as:

 C:\Windows\SysWOW64\config\systemprofile\Desktop

2. The folder(s) need write permission for whatever user is "driving" Office.

Note that, on 64-bit Windows, you need both folders, not just the WOW64 one

 

 

转载于:https://www.cnblogs.com/LegendOfBFS/p/3513439.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值