Soft.xba 9.7 KB

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