1
我嘗試編碼查找&在LibreOffice的Calc中用Python替換方法,用「&」替換所有「。+」(在單個列中 - 不是那麼重要) - 不幸的是,即使是一個標準的查找&替換方法似乎是不可能的(對我來說)。這就是我現在所知道的:Python - LibreOffice Calc - 用正則表達式查找和替換
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
然後會發生什麼:完全沒有!我會很高興和感謝每一個提示,示例代碼和激勵的話!
我對你的代碼做了一些微小的改動,但總的來說它工作得很好。非常感謝! – Elsi