【发布时间】:2016-07-15 07:40:18
【问题描述】:
我尝试在 LibreOffice 的 Calc 中使用 Python 编写查找和替换方法,以将所有“.+”替换为“&”(在单个列中 - 不那么重要) - 不幸的是,即使是标准的查找和替换方法似乎不可能(对我来说)。这就是我现在所拥有的:
import uno
def search()
desktop = XSCRIPTCONTEXT.getDesktop()
document = XSCRIPTCONTEXT.getDocument()
ctx = uno.getComponentContext()
sm = ctx.ServiceManager
dispatcher = sm.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
model = desktop.getCurrentComponent()
doc = model.getCurrentController()
sheet = model.Sheets.getByIndex(0)
replace = sheet.createReplaceDescriptor()
replace.SearchRegularExpression = True
replace.SearchString = ".+$"
replace.ReplaceString ="&"
return None
然后会发生什么:完全没有!我会很高兴并感谢每一个提示、示例代码和激励词!
【问题讨论】:
标签: python libreoffice libreoffice-calc uno