python打开doc提示该文件有宏_LibreOffice如何通过python宏创建文件对话框?

给出并接受答案(因为问题是交叉发布的!)here:import uno

from com.sun.star.beans import PropertyValue

#shortcut:

createUnoService = (

XSCRIPTCONTEXT

.getComponentContext()

.getServiceManager()

.createInstance

)

def pypdf_test():

desktop = XSCRIPTCONTEXT.getDesktop()

doc = desktop.getCurrentComponent()

# filter data

fdata = []

fdata1 = PropertyValue()

fdata1.Name = "SelectPdfVersion"

fdata1.Value = 1

fdata2 = PropertyValue()

fdata2.Name = "Quality"

fdata2.Value = 100

fdata.append(fdata1)

fdata.append(fdata2)

args = []

arg1 = PropertyValue()

arg1.Name = "FilterName"

arg1.Value = "writer_web_pdf_Export"

arg2 = PropertyValue()

arg2.Name = "FilterData"

arg2.Value = uno.Any("[]com.sun.star.beans.PropertyValue", tuple(fdata) )

args.append(arg1)

args.append(arg2)

fileurl = FilePicker()

if fileurl:

doc.storeToURL( fileurl, tuple(args) )

def FilePicker(path=None, mode=1):

"""

Datei öffnen: `mode in (0, 6, 7, 8, 9)`

Datei Schreiben `mode in (1, 2, 3, 4, 5, 10)`

see: ('''http://api.libreoffice.org/docs/idl/ref/

namespacecom_1_1sun_1_1star_1_1ui_1_1

dialogs_1_1TemplateDescription.html''' )

"""

filepicker = createUnoService( "com.sun.star.ui.dialogs.OfficeFilePicker" )

if path:

filepicker.setDisplayDirectory(path )

filepicker.initialize( ( mode,) )

if filepicker.execute():

return filepicker.getFiles()[0]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值