xref: /aoo41x/main/wizards/source/euro/Writer.xba (revision cdf0e10c)
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="Writer" script:language="StarBasic">REM  *****  BASIC  *****
4
5
6Sub ConvertWriterTables()
7Dim CellString as String
8Dim oParagraphs as Object
9Dim oPara as Object
10Dim i as integer
11Dim sCellNames()
12Dim oCell as Object
13	oParagraphs = oDocument.Text.CreateEnumeration
14	While oParagraphs.HasMoreElements
15		oPara = oParagraphs.NextElement
16		If NOT oPara.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
17			&apos; Note: As cells might be splitted or merged
18			&apos; you cannot refer to them via their indices
19			sCellNames = oPara.CellNames
20			For i = 0 To Ubound(sCellNames)
21				If sCellNames(i) &lt;&gt; &quot;&quot; Then
22					oCell = oPara.getCellByName(sCellNames(i))
23					If CheckFormatType(oCell) Then
24						SwitchNumberFormat(oCell, oFormats, sEuroSign)
25						ModifyObjectValuewithCurrFactor(oCell)
26					End If
27				End If
28			Next
29		End If
30	Wend
31End Sub
32
33
34Sub ModifyObjectValuewithCurrFactor(oDocObject as Object)
35	oDocObjectValue = oDocObject.Value
36	oDocObject.Value = oDocObjectValue/CurrFactor
37End Sub
38
39
40Sub ConvertTextFields()
41Dim oTextFields as Object
42Dim oTextField as Object
43Dim FieldValue
44Dim oDocObjectValue as double
45Dim InstanceNames(500) as String
46Dim CurInstanceName as String
47Dim MaxIndex as Integer
48	MaxIndex = 0
49	oTextfields = oDocument.getTextfields.CreateEnumeration
50	While oTextFields.hasmoreElements
51		oTextField = oTextFields.NextElement
52		If oTextField.PropertySetInfo.HasPropertybyName(&quot;NumberFormat&quot;) Then
53			If CheckFormatType(oTextField) Then
54				If oTextField.PropertySetInfo.HasPropertybyName(&quot;Value&quot;) Then
55					If Not oTextField.SupportsService(&quot;com.sun.star.text.TextField.GetExpression&quot;) Then
56						oTextField.Content = CStr(Round(oTextField.Value/CurrFactor,2))
57					End If
58				ElseIf oTextField.TextFieldMaster.PropertySetInfo.HasPropertyByName(&quot;Value&quot;) Then
59					CurInstanceName = oTextField.TextFieldMaster.InstanceName
60					If Not FieldinArray(InstanceNames(), MaxIndex, CurInstanceName) Then
61						oTextField.TextFieldMaster.Content = CStr(Round(oTextField.TextFieldMaster.Value/CurrFactor,2))
62						InstanceNames(MaxIndex) = CurInstanceName
63						MaxIndex = MaxIndex + 1
64					End If
65				End If
66				SwitchNumberFormat(oTextField, oFormats, sEuroSign)
67			End If
68		End If
69	Wend
70	oDocument.GetTextFields.refresh()
71End Sub
72</script:module>