是否有可能确定何时Bookmark
包含TextTable
?我想通过XTextRange
对象来查看,但是,文档没有指定任何关于比较范围的内容。如何检查书签是否包含表格?
0
A
回答
1
所以先从下面的代码:
XBookmarksSupplier xBookmarksSupplier =
(XBookmarksSupplier)UnoRuntime.queryInterface(
XBookmarksSupplier.class, xComponent);
XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();
Object bookmark = xNamedBookmarks.getByName("TextAndTable");
XTextContent xBookmarkContent = (XTextContent)UnoRuntime.queryInterface(
XTextContent.class, bookmark);
XTextRange xTextRange = xBookmarkContent.getAnchor();
这听起来像你问如何确定是否有位于由xTextRange
规定的范围内的一个或多个文本表格。
为此,我通常使用View Cursor。这很慢,但普通文本光标无法遍历不同的文本对象,所以如果范围内有文本表或其他对象,它将会失败。
这里是我的Python类,这或许可以适应的Java:
def differentPlaces(oCurs1, oCurs2):
"""Test using compareRegion to see if two cursors are in different places.
If compareRegion fails, such as after a nested table, return False.
"""
try:
oText = oCurs1.getText()
return oText.compareRegionEnds(oCurs1, oCurs2) != 0
except IllegalArgumentException:
logger.info("Could not compare region.")
return False
class RangeCompare:
"""Compare the viewcursor to a text range (a location).
Can be useful when traversing a cursor over a range.
The range is expected not to be modified.
"""
def __init__(self, rangeEnd, viewCursor):
self.oVC = viewCursor
self.rangeEnd = rangeEnd
self.endX = -1
self.endY = -1
def getCoords(self):
if self.endY > -1:
return
# remember where we were, because we'll need to use the viewcursor
originalVC = self.oVC.getText().createTextCursorByRange(self.oVC)
self.oVC.gotoRange(self.rangeEnd, False)
self.endX = self.oVC.getPosition().X
self.endY = self.oVC.getPosition().Y
self.oVC.gotoRange(originalVC, False)
def compareVC(self):
"""Compare the viewcursor to the range.
Assume we are travelling with the viewcursor.
See if it is up to the end yet or not.
The comparison is done by checking the physical position of the cursor.
Returns -1 if the VC location is less than self.rangeEnd, 0 if it is
the same, and 1 if it is greater.
Returns -2 if they are on the same line but not in the same spot, and
it's not certain which location is greater.
"""
self.getCoords()
curX = self.oVC.getPosition().X
curY = self.oVC.getPosition().Y
if curY < self.endY:
logger.debug("%d < %d", curY, self.endY)
return -1
elif curY > self.endY:
logger.debug("%d > %d", curY, self.endY)
return 1
elif curY == self.endY:
if curX == self.endX:
if differentPlaces(self.oVC, self.rangeEnd):
# There is probably a word-final diacritic that doesn't
# change the position, so we're not to the end yet.
logger.debug("Including word-final diacritic.")
return -2
# We're at the end.
logger.debug(
"VC same loc as text range (%d, %d).", curX, curY)
return 0
else:
logger.debug("Probably haven't gone far enough.")
return -2
实例化类的东西,如rangeCompare = RangeCompare(xTextRange.getEnd(), xViewCursor)
。
将视图光标移动到xTextRange
的开头。然后继续拨打xViewCursor.goRight(1, False)
进行循环。每次检查光标是否位于TextTable中。当rangeCompare.compareVC() > 0
停止。
+0
谢谢你的回答,我会尽快检查 – soon
相关问题
- 1. 如何检测表是否包含表?
- 2. 如何检查DataTable是否包含DataRow?
- 3. 如何检查NSString是否包含'%'?
- 4. 如何检查HashSet是否包含值?
- 5. 如何检查url是否包含“main.php”
- 6. 如何检查CGContext是否包含点?
- 7. 检查表格的单元格是否包含某种形式
- 8. 如何检查标签是否包含特定的字符串?
- 9. 如何检查div标签是否包含部分视图?
- 10. 检查是否包含jQuery
- 11. 检查是否行包含/ *
- 12. 检查列表是否包含密钥
- 13. PHP检查MySQL表是否包含值
- 14. 检查列表是否包含类型?
- 15. 检查数据库是否包含表
- 16. 如何检查字符串是否包含空格
- 17. 如何检查Django表单是否包含任何数据?
- 18. 如何检查表单是否包含单选按钮?
- 19. 如何检查列表是否包含字符串
- 20. 如何检查列表是否包含字节数组?
- 21. 如何检查表是否包含Lua中的元素?
- 22. 如何检查字符串是否包含字符列表?
- 23. 如何检查列表中是否只包含无python
- 24. Longs列表如何检查它是否包含值?
- 25. 序言 - 如何检查列表是否包含某些元素?
- 26. 如何检查嵌套列表是否包含特定值C#
- 27. 如何检查布尔值列表是否包含值?
- 28. Django - 如何检查id是否包含在表列中?
- 29. 序言 - 如何检查列表是否包含某个项目
- 30. JavaScript:如何检查表格的第二列是否包含特定文本
可以肯定的是,你问书签是否位于* TextTable内?这很容易确定。我在下面的回答中假设你的意思是*包含*,如问题所述,并且书签横跨一系列文本而不仅仅是一个位置。 –
不,我在**书签**中询问**表**。 – soon