2007-05-08

スタイルを適用

特定の文字列を検索し、その右隣のセルの内容のスタイルを特定のものに変更します。以下の例は、OpenOffice.orgWriterで、この検索・変更を行うOpenOffice Basicスクリプトです。Winotiaを検索してその右隣のセルの段落にPublic Relationsというスタイルを適用しようとしています。

REM ***** BASIC ***** sub Main rem ---------------------------------------------------------------------- rem define variables dim document as object dim dispatcher as object rem ---------------------------------------------------------------------- rem get access to the document document = ThisComponent.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") rem ---------------------------------------------------------------------- dim args1(18) as new com.sun.star.beans.PropertyValue args1(0).Name = "SearchItem.StyleFamily" args1(0).Value = 2 args1(1).Name = "SearchItem.CellType" args1(1).Value = 0 args1(2).Name = "SearchItem.RowDirection" args1(2).Value = true args1(3).Name = "SearchItem.AllTables" args1(3).Value = false args1(4).Name = "SearchItem.Backward" args1(4).Value = false args1(5).Name = "SearchItem.Pattern" args1(5).Value = true args1(6).Name = "SearchItem.Content" args1(6).Value = false args1(7).Name = "SearchItem.AsianOptions" args1(7).Value = false args1(8).Name = "SearchItem.AlgorithmType" args1(8).Value = 0 args1(9).Name = "SearchItem.SearchFlags" args1(9).Value = 65536 args1(10).Name = "SearchItem.SearchString" args1(10).Value = "Winotia" args1(11).Name = "SearchItem.ReplaceString" args1(11).Value = "" args1(12).Name = "SearchItem.Locale" args1(12).Value = 255 args1(13).Name = "SearchItem.ChangedChars" args1(13).Value = 2 args1(14).Name = "SearchItem.DeletedChars" args1(14).Value = 2 args1(15).Name = "SearchItem.InsertedChars" args1(15).Value = 2 args1(16).Name = "SearchItem.TransliterateFlags" args1(16).Value = 1280 args1(17).Name = "SearchItem.Command" args1(17).Value = 0 args1(18).Name = "Quiet" args1(18).Value = true dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1()) rem ---------------------------------------------------------------------- dispatcher.executeDispatch(document, ".uno:GoToEndOfLine", "", 0, Array()) rem ---------------------------------------------------------------------- dim args3(1) as new com.sun.star.beans.PropertyValue args3(0).Name = "Count" args3(0).Value = 1 args3(1).Name = "Select" args3(1).Value = false dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args3()) rem ---------------------------------------------------------------------- dim args4(0) as new com.sun.star.beans.PropertyValue args4(0).Name = "DesignerDialog" args4(0).Value = true dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args4()) rem ---------------------------------------------------------------------- dim args5(1) as new com.sun.star.beans.PropertyValue args5(0).Name = "Template" args5(0).Value = "Public Relations" args5(1).Name = "Family" args5(1).Value = 2 dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args5()) rem ---------------------------------------------------------------------- dim args6(0) as new com.sun.star.beans.PropertyValue args6(0).Name = "DesignerDialog" args6(0).Value = false dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args6()) end sub

0 件のコメント: