Writer.xba 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--
  4. * This file is part of the LibreOffice project.
  5. *
  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/.
  9. *
  10. * This file incorporates work covered by the following license notice:
  11. *
  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 .
  19. -->
  20. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Writer" script:language="StarBasic">REM ***** BASIC *****
  21. Sub ConvertWriterTables()
  22. Dim CellString as String
  23. Dim oParagraphs as Object
  24. Dim oPara as Object
  25. Dim i as integer
  26. Dim sCellNames()
  27. Dim oCell as Object
  28. oParagraphs = oDocument.Text.CreateEnumeration
  29. While oParagraphs.HasMoreElements
  30. oPara = oParagraphs.NextElement
  31. If NOT oPara.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
  32. &apos; Note: As cells might be split or merged
  33. &apos; you cannot refer to them via their indices
  34. sCellNames = oPara.CellNames
  35. For i = 0 To Ubound(sCellNames)
  36. If sCellNames(i) &lt;&gt; &quot;&quot; Then
  37. oCell = oPara.getCellByName(sCellNames(i))
  38. If CheckFormatType(oCell) Then
  39. SwitchNumberFormat(oCell, oFormats, sEuroSign)
  40. ModifyObjectValuewithCurrFactor(oCell)
  41. End If
  42. End If
  43. Next
  44. End If
  45. Wend
  46. End Sub
  47. Sub ModifyObjectValuewithCurrFactor(oDocObject as Object)
  48. oDocObjectValue = oDocObject.Value
  49. oDocObject.Value = oDocObjectValue/CurrFactor
  50. End Sub
  51. Sub ConvertTextFields()
  52. Dim oTextFields as Object
  53. Dim oTextField as Object
  54. Dim FieldValue
  55. Dim oDocObjectValue as double
  56. Dim InstanceNames(500) as String
  57. Dim CurInstanceName as String
  58. Dim MaxIndex as Integer
  59. MaxIndex = 0
  60. oTextfields = oDocument.getTextfields.CreateEnumeration
  61. While oTextFields.hasmoreElements
  62. oTextField = oTextFields.NextElement
  63. If oTextField.PropertySetInfo.HasPropertybyName(&quot;NumberFormat&quot;) Then
  64. If CheckFormatType(oTextField) Then
  65. If oTextField.PropertySetInfo.HasPropertybyName(&quot;Value&quot;) Then
  66. If Not oTextField.SupportsService(&quot;com.sun.star.text.TextField.GetExpression&quot;) Then
  67. oTextField.Content = CStr(Round(oTextField.Value/CurrFactor,2))
  68. End If
  69. ElseIf oTextField.TextFieldMaster.PropertySetInfo.HasPropertyByName(&quot;Value&quot;) Then
  70. CurInstanceName = oTextField.TextFieldMaster.InstanceName
  71. If Not FieldInArray(InstanceNames(), MaxIndex, CurInstanceName) Then
  72. oTextField.TextFieldMaster.Content = CStr(Round(oTextField.TextFieldMaster.Value/CurrFactor,2))
  73. InstanceNames(MaxIndex) = CurInstanceName
  74. MaxIndex = MaxIndex + 1
  75. End If
  76. End If
  77. SwitchNumberFormat(oTextField, oFormats, sEuroSign)
  78. End If
  79. End If
  80. Wend
  81. oDocument.GetTextFields.refresh()
  82. End Sub
  83. </script:module>