1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <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.
21 ' It works on the currently activated document.
22 Private const UPPERREPLACECHAR =
"X
"
23 Private const LOWERREPLACECHAR =
"x
"
29 Sub ChangeAllChars
' Change all chars in the active document
30 Dim oSheets, oPages as Object
35 BasicLibraries.LoadLibrary(
"Tools
")
36 MSGBOXTITLE =
"Change All Characters to an
'" & UPPERREPLACECHAR
& "'"
37 NOTSAVEDTEXT =
"This document has already been modified: All characters will be changed to an
" & UPPERREPLACECHAR
& "'. Should the document be saved now?
"
38 WARNING =
"This macro changes all characters and numbers to an
'" & UPPERREPLACECHAR
& "' in this document.
"
40 On Local Error GoTo NODOCUMENT
41 oDocument = StarDesktop.ActiveFrame.Controller.Model
43 If Err
<> 0 Then
44 Msgbox(WARNING
& chr(
13)
& "First, activate a Writer document.
" ,
16, GetProductName())
49 sDocType = GetDocumentType(oDocument)
51 If oDocument.IsModified And oDocument.Url
<> "" Then
52 Status = MsgBox(NOTSAVEDTEXT,
3+
32, MSGBOXTITLE)
60 Status = MsgBox(WARNING,
3+
32, MSGBOXTITLE)
61 If Status = MBNO Or Status = MBABORT Then
' No, Abort
67 Case
"swriter
"
68 ReplaceAllStrings(oDocument)
71 Msgbox(
"This macro only works with Writer documents.
",
16, GetProductName())
76 Sub ReplaceAllStrings(oContainer as Object)
77 ReplaceStrings(oContainer,
"[a-z]
", LOWERREPLACECHAR)
78 ReplaceStrings(oContainer,
"[à-þ]
", LOWERREPLACECHAR)
79 ReplaceStrings(oContainer,
"[A-Z]
", UPPERREPLACECHAR)
80 ReplaceStrings(oContainer,
"[À-ß]
", UPPERREPLACECHAR)
81 ReplaceStrings(oContainer,
"[
0-
9]
", UPPERREPLACECHAR)
85 Sub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString as String)
86 oReplaceDesc = oContainer.createReplaceDescriptor()
87 oReplaceDesc.SearchCaseSensitive = True
88 oReplaceDesc.SearchRegularExpression = True
89 oReplaceDesc.Searchstring = sSearchString
90 oReplaceDesc.ReplaceString = sReplaceString
91 oReplCount = oContainer.ReplaceAll(oReplaceDesc)
92 End Sub
</script:module>