xref: /aoo41x/main/wizards/source/euro/Writer.xba (revision 3e02b54d)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Writer" script:language="StarBasic">REM  *****  BASIC  *****
24cdf0e10cSrcweir
25cdf0e10cSrcweir
26cdf0e10cSrcweirSub ConvertWriterTables()
27cdf0e10cSrcweirDim CellString as String
28cdf0e10cSrcweirDim oParagraphs as Object
29cdf0e10cSrcweirDim oPara as Object
30cdf0e10cSrcweirDim i as integer
31cdf0e10cSrcweirDim sCellNames()
32cdf0e10cSrcweirDim oCell as Object
33cdf0e10cSrcweir	oParagraphs = oDocument.Text.CreateEnumeration
34cdf0e10cSrcweir	While oParagraphs.HasMoreElements
35cdf0e10cSrcweir		oPara = oParagraphs.NextElement
36cdf0e10cSrcweir		If NOT oPara.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
37cdf0e10cSrcweir			&apos; Note: As cells might be splitted or merged
38cdf0e10cSrcweir			&apos; you cannot refer to them via their indices
39cdf0e10cSrcweir			sCellNames = oPara.CellNames
40cdf0e10cSrcweir			For i = 0 To Ubound(sCellNames)
41cdf0e10cSrcweir				If sCellNames(i) &lt;&gt; &quot;&quot; Then
42cdf0e10cSrcweir					oCell = oPara.getCellByName(sCellNames(i))
43cdf0e10cSrcweir					If CheckFormatType(oCell) Then
44cdf0e10cSrcweir						SwitchNumberFormat(oCell, oFormats, sEuroSign)
45cdf0e10cSrcweir						ModifyObjectValuewithCurrFactor(oCell)
46cdf0e10cSrcweir					End If
47cdf0e10cSrcweir				End If
48cdf0e10cSrcweir			Next
49cdf0e10cSrcweir		End If
50cdf0e10cSrcweir	Wend
51cdf0e10cSrcweirEnd Sub
52cdf0e10cSrcweir
53cdf0e10cSrcweir
54cdf0e10cSrcweirSub ModifyObjectValuewithCurrFactor(oDocObject as Object)
55cdf0e10cSrcweir	oDocObjectValue = oDocObject.Value
56cdf0e10cSrcweir	oDocObject.Value = oDocObjectValue/CurrFactor
57cdf0e10cSrcweirEnd Sub
58cdf0e10cSrcweir
59cdf0e10cSrcweir
60cdf0e10cSrcweirSub ConvertTextFields()
61cdf0e10cSrcweirDim oTextFields as Object
62cdf0e10cSrcweirDim oTextField as Object
63cdf0e10cSrcweirDim FieldValue
64cdf0e10cSrcweirDim oDocObjectValue as double
65cdf0e10cSrcweirDim InstanceNames(500) as String
66cdf0e10cSrcweirDim CurInstanceName as String
67cdf0e10cSrcweirDim MaxIndex as Integer
68cdf0e10cSrcweir	MaxIndex = 0
69cdf0e10cSrcweir	oTextfields = oDocument.getTextfields.CreateEnumeration
70cdf0e10cSrcweir	While oTextFields.hasmoreElements
71cdf0e10cSrcweir		oTextField = oTextFields.NextElement
72cdf0e10cSrcweir		If oTextField.PropertySetInfo.HasPropertybyName(&quot;NumberFormat&quot;) Then
73cdf0e10cSrcweir			If CheckFormatType(oTextField) Then
74cdf0e10cSrcweir				If oTextField.PropertySetInfo.HasPropertybyName(&quot;Value&quot;) Then
75cdf0e10cSrcweir					If Not oTextField.SupportsService(&quot;com.sun.star.text.TextField.GetExpression&quot;) Then
76cdf0e10cSrcweir						oTextField.Content = CStr(Round(oTextField.Value/CurrFactor,2))
77cdf0e10cSrcweir					End If
78cdf0e10cSrcweir				ElseIf oTextField.TextFieldMaster.PropertySetInfo.HasPropertyByName(&quot;Value&quot;) Then
79cdf0e10cSrcweir					CurInstanceName = oTextField.TextFieldMaster.InstanceName
80cdf0e10cSrcweir					If Not FieldinArray(InstanceNames(), MaxIndex, CurInstanceName) Then
81cdf0e10cSrcweir						oTextField.TextFieldMaster.Content = CStr(Round(oTextField.TextFieldMaster.Value/CurrFactor,2))
82cdf0e10cSrcweir						InstanceNames(MaxIndex) = CurInstanceName
83cdf0e10cSrcweir						MaxIndex = MaxIndex + 1
84cdf0e10cSrcweir					End If
85cdf0e10cSrcweir				End If
86cdf0e10cSrcweir				SwitchNumberFormat(oTextField, oFormats, sEuroSign)
87cdf0e10cSrcweir			End If
88cdf0e10cSrcweir		End If
89cdf0e10cSrcweir	Wend
90cdf0e10cSrcweir	oDocument.GetTextFields.refresh()
91cdf0e10cSrcweirEnd Sub
92*3e02b54dSAndrew Rist</script:module>
93