選択
Writer のいろいろなものを選択します。案外選択状態にするのは難しいです。 選択範囲の取得
現在選択状態のオブジェクトを取得します。 Sub selection_1 oDoc = ThisComponent oSelection = oDoc.getCurrentSelection() End Sub ビューカーソルによる選択
ビューカーソルを移動させてテキストなどを選択状態にできます。ビューカーソル 基本的な選択
基本的に選択するのはコントローラから com.sun.star.util.XSelectable インターフェースの select メソッドを呼び出します。与えるのは大抵の場合選択したいオブジェクトです。 Sub selection_3 oDoc = ThisComponent oController = oDoc.getCurrentController() oController.select(oSomething) End Sub Writer のテキストコンテンツで選択できるのは com.sun.star.text.XTextRange インターフェースをサポートしているオブジェクト(?)。 テキスト
テキストを選択します。 Sub selection_5 oDoc = ThisComponent oControlelr = oDoc.getCurrentController() oText = oDoc.getText() ' End Sub 全選択
oController.select(oText) 文章の最初・最後
文章の一番最初にカーソルが来ます oController.select(oText.getStart()) 文章の最後にカーソルが来ます oController.select(oText.getEnd()) 一部の選択
文章の一部分をテキストカーソルから選択します。以下では文章の最初から 4-5 文字目を選択します。 oCursor = oText.createTextCursor() oCursor.goRight(3, False) oCursor.goRight(2, True) oController.select(oCursor) 段落や行などのテキストカーソルで選択できるものであれば同様に選択できます。 テキストポーションでも同様に選択できます。以下では最初の段落に含まれるテキストポーションを順に選択します。 oParaEnum = oText.createEnumeration() oPara = oParaEnum.nextElement() oPortionEnume = oPara.createEnumeration() While oPortionEnume.hasMoreElements() oPortion = oPortionEnume.nextElement() oController.select(oPortion) WEnd フィールドの選択
フィールドはフィールドからアンカーを取得して選択します。 oFields = oDoc.getTextFields() oFieldsEnume = oFields.createEnumeration() oField = oFieldsEnume.nextElement() oAnchor = oField.getAnchor() oController.select(oAnchor) テキストフレーム
oTextFrames = oDoc.getTextFrames() oTextFrame = oTextFrames.getByIndex(0) oController.select(oTextFrame) 表
表のセル範囲を選択します。なぜか同じ方法では単一のセルを選択できません。 oTables = oDoc.getTextTables() oTable = oTables.getByIndex(0) oCellRange = oTable.getCellRangeByPosition(0, 0, 1, 1) oController.select(oCellRange) 画像
oGraphicObjects = oDoc.getGraphicObjects() oGraphicObject = oGraphicObjects.getByIndex(0) oController.select(oGraphicObject) 図形描写
|