Writer.xba 3.4 KB

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