1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"ChangeAllChars" script:
language=
"StarBasic">' This macro replaces all characters in a writer-documet through
"x
" or
"X
" signs.
4 ' It works on the currently activated document.
5 Private const UPPERREPLACECHAR =
"X
"
6 Private const LOWERREPLACECHAR =
"x
"
12 Sub ChangeAllChars
' Change all chars in the active document
13 Dim oSheets, oPages as Object
18 BasicLibraries.LoadLibrary(
"Tools
")
19 MSGBOXTITLE =
"Change All Characters to an
'" & UPPERREPLACECHAR
& "'"
20 NOTSAVEDTEXT =
"This document has already been modified: All characters will be changed to an
" & UPPERREPLACECHAR
& "'. Should the document be saved now?
"
21 WARNING =
"This macro changes all characters and numbers to an
'" & UPPERREPLACECHAR
& "' in this document.
"
23 On Local Error GoTo NODOCUMENT
24 oDocument = StarDesktop.ActiveFrame.Controller.Model
26 If Err
<> 0 Then
27 Msgbox(WARNING
& chr(
13)
& "First, activate a Writer document.
" ,
16, GetProductName())
32 sDocType = GetDocumentType(oDocument)
34 If oDocument.IsModified And oDocument.Url
<> "" Then
35 Status = MsgBox(NOTSAVEDTEXT,
3+
32, MSGBOXTITLE)
43 Status = MsgBox(WARNING,
3+
32, MSGBOXTITLE)
44 If Status = MBNO Or Status = MBABORT Then
' No, Abort
50 Case
"swriter
"
51 ReplaceAllStrings(oDocument)
54 Msgbox(
"This macro only works with Writer documents.
",
16, GetProductName())
59 Sub ReplaceAllStrings(oContainer as Object)
60 ReplaceStrings(oContainer,
"[a-z]
", LOWERREPLACECHAR)
61 ReplaceStrings(oContainer,
"[à-þ]
", LOWERREPLACECHAR)
62 ReplaceStrings(oContainer,
"[A-Z]
", UPPERREPLACECHAR)
63 ReplaceStrings(oContainer,
"[À-ß]
", UPPERREPLACECHAR)
64 ReplaceStrings(oContainer,
"[
0-
9]
", UPPERREPLACECHAR)
68 Sub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString as String)
69 oReplaceDesc = oContainer.createReplaceDescriptor()
70 oReplaceDesc.SearchCaseSensitive = True
71 oReplaceDesc.SearchRegularExpression = True
72 oReplaceDesc.Searchstring = sSearchString
73 oReplaceDesc.ReplaceString = sReplaceString
74 oReplCount = oContainer.ReplaceAll(oReplaceDesc)
75 End Sub
</script:module>