* 選択 [#d66ce461] Writer のいろいろなものを選択します。案外選択状態にするのは難しいです。 #contents ** 選択範囲の取得 [#jc9b06ac] 現在選択状態のオブジェクトを取得します。 Sub selection_1 oDoc = ThisComponent oSelection = oDoc.getCurrentSelection() End Sub ** ビューカーソルによる選択 [#rf3af74a] ビューカーソルを移動させてテキストなどを選択状態にできます。[[ビューカーソル>../ViewCursor]] ** 基本的な選択 [#n085da85] 基本的に選択するのはコントローラから 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 インターフェースをサポートしているオブジェクト(?)。 ** テキスト [#t83295c6] テキストを選択します。 Sub selection_5 oDoc = ThisComponent oControlelr = oDoc.getCurrentController() oText = oDoc.getText() ' End Sub *** 全選択 [#e8aa808e] oController.select(oText) *** 文章の最初・最後 [#se2fd1af] 文章の一番最初にカーソルが来ます oController.select(oText.getStart()) 文章の最後にカーソルが来ます oController.select(oText.getEnd()) *** 一部の選択 [#tb584eb0] 文章の一部分をテキストカーソルから選択します。以下では文章の最初から 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 ** フィールドの選択 [#nc8429e9] フィールドはフィールドからアンカーを取得して選択します。 oFields = oDoc.getTextFields() oFieldsEnume = oFields.createEnumeration() oField = oFieldsEnume.nextElement() oAnchor = oField.getAnchor() oController.select(oAnchor) ** テキストフレーム [#l31e7ee0] oTextFrames = oDoc.getTextFrames() oTextFrame = oTextFrames.getByIndex(0) oController.select(oTextFrame) ** 表 [#h6b97cc0] 表のセル範囲を選択します。なぜか同じ方法では単一のセルを選択できません。 oTables = oDoc.getTextTables() oTable = oTables.getByIndex(0) oCellRange = oTable.getCellRangeByPosition(0, 0, 1, 1) oController.select(oCellRange) ** 画像 [#v76fed7d] oGraphicObjects = oDoc.getGraphicObjects() oGraphicObject = oGraphicObjects.getByIndex(0) oController.select(oGraphicObject) ** 図形描写 [#g42d27c5] |