Soft.xba 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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="Soft" script:language="StarBasic">Option Explicit
  21. REM ***** BASIC *****
  22. Sub CreateStyleEnumeration()
  23. EmptySelection()
  24. EmptyListbox(DialogModel.lstSelection)
  25. CurSheetName = oDocument.CurrentController.GetActiveSheet.Name
  26. MakeStyleEnumeration(False)
  27. DialogModel.lblSelection.Label = sTEMPLATES
  28. End Sub
  29. Sub MakeStyleEnumeration(bAddToListbox as Boolean)
  30. Dim m as integer
  31. Dim aStyleFormat as Object
  32. Dim Stylename as String
  33. StyleIndex = -1
  34. oStyles = oDocument.StyleFamilies.GetbyIndex(0)
  35. For m = 0 To oStyles.count-1
  36. oStyle = oStyles.GetbyIndex(m)
  37. StyleName = oStyle.Name
  38. If CheckFormatType(oStyle) Then
  39. If Not bAddToListBox Then
  40. AddSingleItemToListbox(DialogModel.lstSelection, Stylename)
  41. Else
  42. SwitchNumberFormat(ostyle, oFormats, sEuroSign)
  43. End If
  44. StyleIndex = StyleIndex + 1
  45. If StyleIndex &gt; Ubound(StyleRangeAssignMentList()) Then
  46. Redim Preserve StyleRangeAssignmentList(StyleIndex)
  47. End If
  48. StyleRangeAssignmentList(StyleIndex) = &quot;&lt;STYLENAME&gt;&quot; &amp; Stylename &amp; &quot;&lt;/STYLENAME&gt;&quot; &amp; _
  49. &quot;&lt;DEFINED&gt;FALSE&lt;/DEFINED&gt;&quot; &amp; &quot;&lt;RANGES&gt;&lt;/RANGES&gt;&quot; &amp;_
  50. &quot;&lt;CELLCOUNT&gt;0&lt;/CELLCOUNT&gt;&quot; &amp;_
  51. &quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;
  52. End If
  53. Next m
  54. If StyleIndex &gt; -1 Then
  55. Redim Preserve StyleRangeAssignmentList(StyleIndex)
  56. Else
  57. ReDim StyleRangeAssignmentList()
  58. End If
  59. End Sub
  60. Sub AssignRangestoStyle(StyleList(), SelList())
  61. Dim i as Integer
  62. Dim n as integer
  63. Dim LastIndex as Integer
  64. Dim CurStyleName as String
  65. Dim AssignString as String
  66. LastIndex = Ubound(StyleList())
  67. StatusValue = 0
  68. SetStatusLineText(sStsRELRANGES)
  69. For i = 0 To LastIndex
  70. CurStyleName = StyleList(i)
  71. n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName, 0)
  72. AssignString = StyleRangeAssignmentlist(n)
  73. If IndexInArray(CurStyleName, SelList()) &lt;&gt; -1 Then
  74. &apos; Style is selected
  75. If FindPartString(AssignString, &quot;&lt;DEFINED&gt;&quot;, &quot;&lt;/DEFINED&gt;&quot;, 1) = &quot;FALSE&quot; Then
  76. AssignString = ReplaceString(AssignString, &quot;&lt;SELECTED&gt;TRUE&lt;/SELECTED&gt;&quot;, &quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;)
  77. AssignCellFormatRanges(n, AssignString, CurStyleName)
  78. End If
  79. Else
  80. &apos; Style is not selected
  81. If FindPartString(AssignString, &quot;&lt;SELECTED&gt;&quot;, &quot;&lt;/SELECTED&gt;&quot;, 1) = &quot;FALSE&quot; Then
  82. DeselectStyle(CurStyleName, n)
  83. End If
  84. End If
  85. IncreaseStatusvalue(SBRELGET/(LastIndex+1))
  86. Next i
  87. End Sub
  88. Sub AssignCellFormatRanges(n as Integer, AssignString as String, CurStyleName as String)
  89. Dim oRanges() as Object
  90. Dim oRange as Object
  91. Dim oRangeAddress
  92. Dim oSheet as Object
  93. Dim StyleCellCount as Long
  94. Dim i as Integer
  95. Dim MaxIndex as Integer
  96. Dim RangeString as String
  97. Dim SheetName as String
  98. Dim RangeName as String
  99. Dim CellCountString as String
  100. StyleCellCount = 0
  101. RangeString = &quot;&lt;RANGES&gt;&quot;
  102. MaxIndex = oSheets.Count-1
  103. For i = 0 To MaxIndex
  104. oSheet = oSheets(i)
  105. SheetName = oSheet.Name
  106. oRanges = osheet.CellFormatRanges.CreateEnumeration
  107. While oRanges.hasMoreElements
  108. oRange = oRanges.NextElement
  109. If oRange.getPropertyState(&quot;NumberFormat&quot;) = 1 Then
  110. If oRange.CellStyle = CurStyleName Then
  111. oRangeAddress = oRange.RangeAddress
  112. RangeName = RetrieveRangeNamefromAddress(oRange)
  113. RangeString = RangeString &amp; RangeName &amp; &quot;,&quot;
  114. StyleCellCount = StyleCellCount + CountRangeCells(oRange)
  115. End If
  116. End If
  117. Wend
  118. Next i
  119. If StyleCellCount &gt; 0 Then
  120. TotCellCount = TotCellCount + StyleCellCount
  121. RangeString = RTrimStr(RangeString,&quot;,&quot;)
  122. RangeString = RangeString &amp; &quot;&lt;/RANGES&gt;&quot;
  123. CellCountString = &quot;&lt;CELLCOUNT&gt;&quot; &amp; StyleCellCount &amp; &quot;&lt;/CELLCOUNT&quot;
  124. AssignString = ReplaceString(AssignString, RangeString,&quot;&lt;RANGES&gt;&lt;/RANGES&gt;&quot;)
  125. AssignString = ReplaceString(AssignString, CellCountString,&quot;&lt;CELLCOUNT&gt;0&lt;/CELLCOUNT&gt;&quot;)
  126. End If
  127. AssignString = ReplaceString(AssignString, &quot;&lt;DEFINED&gt;TRUE&lt;/DEFINED&gt;&quot;, &quot;&lt;DEFINED&gt;FALSE&lt;/DEFINED&gt;&quot;)
  128. StyleRangeAssignmentList(n) = AssignString
  129. End Sub
  130. &apos; deletes a styletemplate from the Collection that selects the ranges
  131. Sub DeselectStyle(DeSelStyleName as String, n as Integer)
  132. Dim i as Integer
  133. Dim RangeName as String
  134. Dim SelectString as String
  135. Dim AssignString as String
  136. Dim StyleRangeList() as String
  137. Dim MaxIndex as Integer
  138. SelectString =&quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;
  139. AssignString = StyleRangeAssignmentList(n)
  140. RangeString = FindPartString(AssignString,&quot;&lt;RANGES&gt;&quot;,&quot;&lt;/RANGES&gt;&quot;,1)
  141. StyleRangeList() = ArrayoutofString(RangeString,&quot;,&quot;)
  142. MaxIndex = Ubound(StyleRangeList())
  143. For i = 0 To MaxIndex
  144. RangeName = StyleRangeList(i)
  145. If oSelRanges.HasbyName(RangeName) Then
  146. oSelRanges.RemovebyName(RangeName)
  147. End If
  148. Next i
  149. AssignString = ReplaceString(AssignString, &quot;&lt;SELECTED&gt;FALSE&lt;/SELECTED&gt;&quot;, &quot;&lt;SELECTED&gt;TRUE&lt;/SELECTED&gt;&quot;)
  150. StyleRangeAssignmentList(n) = AssignString
  151. End Sub
  152. Function RetrieveRangeNamefromAddress(oRange as Object) as String
  153. Dim Rangename as String
  154. Dim oAddressRanges as Object
  155. oAddressRanges = oDocument.createInstance(&quot;com.sun.star.sheet.SheetCellRanges&quot;)
  156. oAddressRanges.InsertbyName(&quot;&quot;,oRange)
  157. Rangename = oAddressRanges.RangeAddressesasString
  158. &apos; Msgbox &quot;Adresse: &quot; &amp; oRangeAddress.StartColumn &amp; &quot; ; &quot; &amp; oRangeAddress.EndColumn &amp; &quot; ; &quot; &amp; oRangeAddress.StartRow &amp; &quot; ; &quot; &amp; oRangeAddress.EndRow &amp; chr(13) &amp; RangeName
  159. &apos; oAddressRanges.RemovebyName(RangeName)
  160. RetrieveRangeNamefromAddress = Rangename
  161. End Function
  162. &apos; creates a sheet object from an according sectionname
  163. Function RetrieveSheetoutofRangeName(TableText as String)
  164. Dim DescriptionList() as String
  165. Dim SheetName as String
  166. Dim MaxIndex as integer
  167. &apos; find out in which sheet the range is
  168. DescriptionList() = ArrayOutofString(TableText,&quot;.&quot;,MaxIndex)
  169. SheetName = DescriptionList(0)
  170. SheetName = DeleteStr(SheetName,&quot;&apos;&quot;)
  171. &apos; set the viewcursor on this sheet
  172. RetrieveSheetoutofRangeName = oSheets.GetbyName(SheetName)
  173. End Function
  174. &apos; creates a rangeobject from an according rangename
  175. Function RetrieveRangeoutofRangeName(TableText as String)
  176. oSheet = RetrieveSheetoutofRangeName(TableText)
  177. oRange = oSheet.GetCellRangebyName(TableText)
  178. RetrieveRangeoutofRangeName = oRange
  179. End Function
  180. Sub ConvertTheSoftWay(StyleList(), bDeSelect as Boolean)
  181. Dim i as Integer
  182. Dim l as Integer
  183. Dim s as Integer
  184. Dim n as Integer
  185. Dim CurStyleName as String
  186. Dim RangeName as String
  187. Dim OldStatusValue as Integer
  188. Dim LastIndex as Integer
  189. Dim oSelListbox as Object
  190. Dim StyleRangeList() as String
  191. Dim MaxIndex as Integer
  192. oSelListbox = DialogConvert.GetControl(&quot;lstSelection&quot;)
  193. LastIndex = Ubound(StyleList())
  194. OldStatusValue = StatusValue
  195. For i = 0 To LastIndex
  196. CurStyleName = StyleList(i)
  197. oStyle = oStyles.GetbyName(CurStyleName)
  198. StyleRangeList() = GetAssignedRanges(CurStyleName, n)
  199. MaxIndex = Ubound(StyleRangeList())
  200. For s = 0 To MaxIndex
  201. RangeName = StyleRangeList(s)
  202. oRange = RetrieveRangeoutofRangeName(RangeName)
  203. If oRange.getPropertyState(&quot;NumberFormat&quot;) = 1 Then
  204. &apos; Range is hard formatted
  205. ConvertCellCurrencies(oRange)
  206. CurCellCount = CountRangeCells(oRange)
  207. End If
  208. IncreaseStatusvalue((CurCellCount/TotCellCount)*(95-OldStatusValue))
  209. If bDeSelect Then
  210. &apos; Note: On Problems see Bug #73157
  211. If oSelRanges.HasbyName(RangeName) Then
  212. oSelRanges.RemovebyName(RangeName)
  213. oDocument.CurrentController.Select(oSelRanges)
  214. End If
  215. End If
  216. Next s
  217. SwitchNumberFormat(ostyle, oFormats, sEuroSign)
  218. StyleRangeAssignmentList(n) = &quot;&quot;
  219. l = GetItemPos(oSelListBox.Model, CurStyleName)
  220. oSelListbox.RemoveItems(l,1)
  221. Next
  222. End Sub
  223. Function GetAssignedRanges(CurStyleName as String, n as Integer)
  224. Dim StyleRangeList() as String
  225. Dim RangeString as String
  226. Dim AssignString as String
  227. n = PartStringInArray(StyleRangeAssignmentList(), CurStyleName, 0)
  228. If n &lt;&gt; -1 Then
  229. AssignString = StyleRangeAssignmentList(n)
  230. RangeString = FindPartString(AssignString,&quot;&lt;RANGES&gt;&quot;, &quot;&lt;/RANGES&gt;&quot;,1)
  231. If RangeString &lt;&gt; &quot;&quot; Then
  232. StyleRangeList() = ArrayoutofString(RangeString,&quot;,&quot;)
  233. End If
  234. End If
  235. GetAssignedRanges() = StyleRangeList()
  236. End Function</script:module>