- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
LibreOffice writer 允许用户在文本中插入注释(注释/评论)。
我的问题是我无法找到访问特定行注释内容的方法。
以下 python 代码查找选定/突出显示的文本,然后删除除格式化时间代码(例如 01:10:23 或 11:10)之外的所有内容,并将其转换为秒。
如果未选择任何文本,它将选择整个当前行并尝试查找时间代码。但是,时间代码可以位于注释中。
我已经设法获得文档中所有注释的列表,并在代码开头注释掉,但这对我来说没有用。
我一直无法找到占卜的方法
a) 当前行是否有注释或
b) 如何访问其内容。
如果有人成功实现了这一点,我将不胜感激。
def fs2_GoToTimestamp(*args):
#get the doc from the scripting context which is made available to all scripts
desktop = XSCRIPTCONTEXT.getDesktop()
model = desktop.getCurrentComponent()
oSelected = model.getCurrentSelection()
#access annotations for the whole document
# oEnum = model.getTextFields().createEnumeration()
# cursor = desktop.getCurrentComponent().getCurrentController().getViewCursor()
# while oEnum.hasMoreElements():
# oField = oEnum.nextElement()
# cursor.gotoRange(oField,False)
# print (cursor.getPosition())
# if oField.supportsService('com.sun.star.text.TextField.Annotation'):
# print (oField.Content)
# x = oField.getAnchor()
# print (dir(x))
oText = ""
try: #Grab the text selected/highlighted
oSel = oSelected.getByIndex(0)
oText= oSel.getString()
except:pass
try:
if oText == "": # Nothing selected grab the whole line
cursor = desktop.getCurrentComponent().getCurrentController().getViewCursor()
cursor.gotoStartOfLine(False) #move cursor to start without selecting (False)
cursor.gotoEndOfLine(True) #now move cursor to end of line selecting all (True)
oSelected = model.getCurrentSelection()
oSel = oSelected.getByIndex(0)
oText= oSel.getString()
# Deselect line to avoid inadvertently deleting it on next keystroke
cursor.gotoStartOfLine(False)
except:pass
time = str(oText)
valid_chars=('0123456789:')
time = ''.join(char for char in time if char in valid_chars)
if time.count(":") == 1:
oM, oS = time.split(":")
oH = "00"
elif time.count(":") == 2:
oH,oM,oS = time.split(":")
else:
return None
if len(oS) != 2:
oS=oS[:2]
try:
secs = int(oS)
secs = secs + int(oM) * 60
secs = secs + int(oH) *3600
except:
return None
seek_instruction = 'seek'+str(secs)+'\n'
#Now do something with the seek instruction
最佳答案
枚举annotations并使用getAnchor()找出每个位置的位置。此答案基于https://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Editing_Text#Text_Contents_Other_Than_Strings .
您的代码即将运行。
while oEnum.hasMoreElements():
oField = oEnum.nextElement()
if oField.supportsService('com.sun.star.text.TextField.Annotation'):
xTextRange = oField.getAnchor()
cursor.gotoRange(xTextRange, False)
XrayTool 或 MRI 等内省(introspection)工具可以提供更好的信息,而不是 print (dir(x))
。它使 API 文档更容易理解。
关于python - 如何从 python 宏读取 LibreOffice writer 注释的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44703487/
我有一个函数可以将数据写入任何实现接口(interface)的对象,该接口(interface)使用 Write(b []byte) (n int, err error) 方法。现在在我的程序中,我写
我继承了一些 Java。我对其他类似 C 的语言有很多经验,但我对 Java 还是很陌生。在一个函数中,我的前任同时使用了 write()和 append() Writer 的方法类,但我不明白为什么
我继承了一些 Java。我对其他类似 C 的语言有很多经验,但我对 Java 还是很陌生。在一个函数中,我的前任同时使用了 write()和 append() Writer 的方法类,但我不明白为什么
假设这里唯一的区别是二进制读取器/写入器对字符串使用固定长度编码,因此可能效率较低,是否正确? 最佳答案 不存在大量其他差异,例如读取和写入行、编码...基本上是与文本相关的“帮助器”函数的负载。 关
在将有效负载发送到 Web 服务之前尝试将有效负载转换为 xml 时,我在 mule 独立版本 3.8.1 中遇到错误。 我的流程配置是这样的:
似乎有两种方法可以将 JSON 对象的内容写入编写器。我可以做 myWriter.write(myJSONObj.toString()); 或者 myJSONObj.write(myWriter);
这个问题已经有答案了: Should one call .close() on HttpServletResponse.getOutputStream()/.getWriter()? (6 个回答)
初始化记录器后: var Logger *log.Logger f, err := os.OpenFile("somefile", os.O_WRONLY|os.O_CREATE|os.O_APPEN
我正在开发一个网站,除其他外,它通过 Metaweblog API 提供博客。我已经让 API 与几个博客客户端一起工作得很好,但 Windows Live Writer 正在扼杀我。 我已经完成了网
我有一个在启动后异步运行的方法,使用 OutputStream 或 Writer 作为参数。 它充当 OutputStream 或 Writer 的记录适配器(这是我无法更改的第三方 API)。 如何
我正在使用 ruby version 1.9.3 并且在启动 thin server 时出现错误 /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.1
我编辑了一个来自客户的文档,其中有一些亮点,然后决定删除评论中的亮点。 无论出于何种原因,该文档突出显示了许多项目符号和编号列表部分,当我尝试选择整个文档并将突出显示更改为“无填充”时,我无法还原这些
我正在读取 URL 的内容并将其写入文件,这按预期工作,但即使程序控制台显示多行,它也只写入一次。 代码: PrintWriter writer = new PrintWriter("the-file
在调用 XslCompiledTransform.Transform() 方法时出现此异常: The Writer is closed or in error state. 谁知道这是什么意思? 最佳
我试图制作一个系统,用于将 lua 编译脚本存储在内存中。问题是我不能做一个“lua_Writer”,变量字节码是空的。我使用 Luajit。在我的代码下方。 typedef struct {
我想将一些字符串写入文件。所以,我使用了 BufferedWriter 类。由于许多线程倾向于写入该文件,我想知道 write 和 writeLine 方法是否是原子的。 此外,我希望程序将输出写入多
我有一个套接字,我可以在其中写入一些字符数据和一些原始字节数据。对于字符数据,使用PrintWriter 更容易。对于原始字节数据,直接写入 OutputStream 会更容易。所以在我的代码中,我有
在 Golang 中是否可以将 string 转换为 io.Writer 类型? 我将在 fmt.Fprintf() 中使用此字符串,但我无法转换类型。 最佳答案 你不能写入 string,strin
我正在将数据框拧到 Excel 中。也许我做得不对, 当我使用此代码时: from datetime import datetime import numpy as np import pandas
我尝试导入 Control.Monad.Writer像这样的模块: import Control.Monad.Writer ghc版本 7.4.1 给出以下错误: Ambiguous module n
我是一名优秀的程序员,十分优秀!