home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0179 / Misc.xba < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-08  |  22.9 KB  |  709 lines

  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="Misc" script:language="StarBasic">REM  *****  BASIC  *****
  4.  
  5. Const SBSHARE = 0
  6. Const SBUSER = 1
  7. Dim Taskindex as Integer
  8. Dim oResSrv as Object
  9.  
  10. Sub Main()
  11. Dim PropList(3,1)' as String
  12.     PropList(0,0) = "URL"
  13.     PropList(0,1) = "sdbc:odbc:Erica_Test_Unicode"
  14.     PropList(1,0) = "User"
  15.     PropList(1,1) = "extra"
  16.     PropList(2,0) = "Password"
  17.     PropList(2,1) = "extra"
  18.     PropList(3,0) = "IsPasswordRequired"
  19.     PropList(3,1) = True
  20. '    RegisterNewDataSource("Doc_Erica_Test_Unicode", PropList())
  21. End Sub
  22.  
  23.  
  24. Function RegisterNewDataSource(DSName as  String, PropertyList(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue)
  25. Dim oDataSource as Object
  26. Dim oDBContext as Object
  27. Dim oPropInfo as Object
  28. Dim i as Integer
  29.     oDBContext = createUnoService("com.sun.star.sdb.DatabaseContext")
  30.     oDataSource = createUnoService("com.sun.star.sdb.DataSource")
  31.     For i = 0 To Ubound(PropertyList(), 1)
  32.         sPropName = PropertyList(i,0)
  33.         sPropValue = PropertyList(i,1)
  34.         oDataSource.SetPropertyValue(sPropName,sPropValue) 'GetByName(sPropName) = sPropValue 'oPropInfo.GetPropertyByName(sPropName)) = sPropValue '  PropertyList(i,0))) = PropertyList(i,1)
  35.     Next i
  36.     If Not IsMissing(DriverProperties()) Then
  37.         oDataSource.Info() = DriverProperties()
  38.     End If
  39.     oDBContext.RegisterObject(DSName, oDataSource)
  40.     RegisterNewDataSource () = oDataSource
  41. End Function
  42.  
  43.  
  44. ' Connects to a registered Database
  45. Function ConnecttoDatabase(DSName as String, UserID as String, Password as String, Optional Propertylist(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue)
  46. Dim oDBContext as Object
  47. Dim oDBSource as Object
  48. '    On Local Error Goto NOCONNECTION
  49.     oDBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
  50.     If oDBContext.HasbyName(DSName) Then
  51.         oDBSource = oDBContext.GetByName(DSName)
  52.         ConnectToDatabase = oDBSource.GetConnection(UserID, Password)
  53.     Else
  54.         If Not IsMissing(Namelist()) Then
  55.             If Not IsMissing(DriverProperties()) Then
  56.                 RegisterNewDataSource(DSName, PropertyList(), DriverProperties())
  57.             Else
  58.                 RegisterNewDataSource(DSName, PropertyList())
  59.             End If
  60.             oDBSource = oDBContext.GetByName(DSName)
  61.             ConnectToDatabase = oDBSource.GetConnection(UserID, Password)        
  62.         Else
  63.             Msgbox("DataSource " & DSName & " is not registered" , 16, GetProductname())
  64.             ConnectToDatabase() = NULL
  65.         End If
  66.     End If
  67. NOCONNECTION:
  68.     If Err <> 0 Then
  69.         Msgbox(Error$, 16, GetProductName())
  70.         Resume LEAVESUB
  71.         LEAVESUB:
  72.     End If    
  73. End Function
  74.  
  75.  
  76. Function GetStarOfficeLocale() as New com.sun.star.lang.Locale
  77. Dim aLocLocale As New com.sun.star.lang.Locale
  78. Dim sLocale as String
  79. Dim sLocaleList(1)
  80. Dim oMasterKey
  81.     oMasterKey = GetRegistryKeyContent("org.openoffice.Setup/L10N/")
  82.     sLocale = oMasterKey.getByName("ooLocale")
  83.     sLocaleList() = ArrayoutofString(sLocale, "-")
  84.     aLocLocale.Language = sLocaleList(0)
  85.     If Ubound(sLocaleList()) > 0 Then
  86.         aLocLocale.Country = sLocaleList(1)
  87.     End If
  88.     GetStarOfficeLocale() = aLocLocale
  89. End Function
  90.  
  91.  
  92. Function GetRegistryKeyContent(sKeyName as string)
  93. Dim oConfigProvider as Object
  94. Dim aNodePath(0) as new com.sun.star.beans.PropertyValue
  95.     oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
  96.     aNodePath(0).Name = "nodepath"
  97.     aNodePath(0).Value = sKeyName
  98.     GetRegistryKeyContent = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath())
  99. End Function
  100.  
  101.  
  102. Function GetProductname() as String
  103. Dim oProdNameAccess as Object
  104. Dim omyNames(100) as Object
  105. Dim sVersion as String
  106. Dim sProdName as String
  107.     oProdNameAccess = GetRegistryKeyContent("org.openoffice.Setup/Product")
  108.     sProdName = oProdNameAccess.getByName("ooName")
  109.     sVersion = oProdNameAccess.getByName("ooSetupVersion")
  110.     GetProductName = sProdName & "." & sVersion
  111. End Function
  112.  
  113.  
  114. ' Opens a Document, checks beforehand, wether it has to be loaded
  115. ' or wether it is already on the desktop
  116. Function OpenDocument(DocPath as String, Args())
  117. Dim oComponents as Object
  118. Dim oComponent as Object
  119.     ' Search if one of the active Components ist the one that you search for
  120.     oComponents = StarDesktop.Components.CreateEnumeration
  121.     While oComponents.HasmoreElements
  122.         oComponent = oComponents.NextElement
  123.             If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") then
  124.             If UCase(oComponent.URL) = UCase(DocPath) then
  125.                 OpenDocument() = oComponent
  126.                 Exit Function
  127.             End If
  128.         End If
  129.     Wend
  130.     OpenDocument() = StarDesktop.LoadComponentFromURL(DocPath,"_blank",0,Args())
  131. End Function
  132.  
  133.  
  134. Function TaskonDesktop(DocPath as String) as Boolean
  135. Dim oComponents as Object
  136. Dim oComponent as Object
  137.     ' Search if one of the active Components ist the one that you search for
  138.     oComponents = StarDesktop.Components.CreateEnumeration
  139.     While oComponents.HasmoreElements
  140.         oComponent = oComponents.NextElement
  141.             If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") then
  142.             If UCase(oComponent.URL) = UCase(DocPath) then
  143.                 TaskonDesktop = True
  144.                 Exit Function
  145.             End If
  146.         End If
  147.     Wend
  148.     TaskonDesktop = False
  149. End Function
  150.  
  151.  
  152. ' Retrieves a FileName out of a StarOffice-Document
  153. Function RetrieveFileName(LocDoc as Object)
  154. Dim LocURL as String
  155. Dim LocURLArray() as String
  156. Dim MaxArrIndex as integer
  157.  
  158.     LocURL = LocDoc.Url
  159.     LocURLArray() = ArrayoutofString(LocURL,"/",MaxArrIndex)
  160.     RetrieveFileName = LocURLArray(MaxArrIndex)
  161. End Function
  162.  
  163.  
  164. ' Gets a special configured PathSetting
  165. Function GetPathSettings(sPathType as String,  Optional bshowall as Boolean, Optional ListIndex as integer) as String
  166. Dim oSettings, oPathSettings as Object
  167. Dim sPath as String
  168. Dim PathList() as String
  169. Dim MaxIndex as Integer
  170.  
  171.     oSettings = createUnoService("com.sun.star.frame.Settings")
  172.     oPathSettings = oSettings.getByName("PathSettings")
  173.       If Not IsMissing(bShowall) Then
  174.         If bShowAll Then
  175.             ShowPropertyValues(oPathSettings)
  176.             Exit Function
  177.         End If
  178.     End If
  179.      sPath = oPathSettings.GetPropertyValue(sPathType)
  180.     If Not IsMissing(ListIndex) Then
  181.         ' Share and User-Directory
  182.         If Instr(1,sPath,";") <> 0 Then
  183.             PathList = ArrayoutofString(sPath,";", MaxIndex)
  184.             If ListIndex <= MaxIndex Then
  185.                 sPath = PathList(ListIndex)
  186.             Else
  187.                 Msgbox("Cannot analyze the String " & sPath , 16, GetProductName())
  188.             End If
  189.         End If
  190.     End If
  191.     If Instr(1, sPath, ";") = 0 Then
  192.         GetPathSettings = ConvertToUrl(sPath)
  193.     Else
  194.         GetPathSettings = sPath
  195.     End If
  196. End Function
  197.  
  198.  
  199.  
  200. ' Gets the fully qualified path to a subdirectory of the
  201. ' Template Directory, e. g. with the parameter "wizard/bitmap"
  202. ' The parameter must be passed over in Url-scription
  203. ' The return-Value is in Urlscription
  204. Function GetOfficeSubPath(sOfficePath as String, ByVal sSubDir as String)
  205. Dim oUcb as Object
  206. Dim sOfficeString as String
  207. Dim sOfficeList() as String
  208. Dim sOfficeDir as String
  209. Dim sBigDir as String
  210. Dim i as Integer
  211. Dim MaxIndex as Integer
  212.     oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
  213.     sOfficeString = GetPathSettings(sOfficePath)
  214.     If Right(sSubDir,1) <> "/" Then
  215.         sSubDir = sSubDir & "/"
  216.     End If
  217.     sOfficeList() = ArrayoutofString(sOfficeString,";", MaxIndex)
  218.     For i = 0 To MaxIndex
  219.         sOfficeDir = ConvertToUrl(sOfficeList(i))
  220.         If Right(sOfficeDir,1) <> "/" Then
  221.             sOfficeDir = sOfficeDir & "/"
  222.         End If
  223.         sBigDir = sOfficeDir & sSubDir
  224.         If oUcb.Exists(sBigDir) Then
  225.             GetOfficeSubPath() = sBigDir
  226.             Exit Function
  227.         End If
  228.     Next i
  229.     GetOfficeSubPath = ""
  230. End Function
  231.  
  232.  
  233.  
  234. Function InitResources(Description, ShortDescription as String) as boolean
  235.     On Error Goto ErrorOcurred
  236.     oResSrv = createUnoService( "com.sun.star.resource.VclStringResourceLoader" )
  237.     If (IsNull(oResSrv)) then
  238.         InitResources = FALSE
  239.         MsgBox( Description & ": No resource loader found", 16, GetProductName())
  240.     Else
  241.         InitResources = TRUE
  242.         oResSrv.FileName = ShortDescription
  243.     End If
  244.     Exit Function
  245. ErrorOcurred:
  246.     Dim nSolarVer
  247.     InitResources = FALSE
  248.     nSolarVer = GetSolarVersion()
  249.     MsgBox("Resource file missing (" & ShortDescription  & trim(str(nSolarVer)) + "*.res)", 16, GetProductName())
  250.     Resume CLERROR
  251.     CLERROR:
  252. End Function
  253.  
  254.  
  255. Function GetResText( nID as integer ) As string
  256.     On Error Goto ErrorOcurred
  257.     If Not IsNull(oResSrv) Then
  258.         ' eigentlich sollte hier stehen
  259.         GetResText = oResSrv.getString( nID )
  260.     Else
  261.         GetResText = ""
  262.     End If
  263.     Exit Function
  264. ErrorOcurred:
  265.     GetResText = ""
  266.     MsgBox("Resource with ID =" + str( nID ) + " not found!", 16, GetProductName())
  267.     Resume CLERROR
  268.     CLERROR:
  269. End Function
  270.  
  271.  
  272. Function CutPathView(sDocUrl as String, PathLen as Integer)
  273. Dim sViewPath as String
  274.     sViewPath = ConvertfromURL(sDocURL)
  275.     iViewPathLen = Len(sViewPath)
  276.     If iViewPathLen > 60 Then
  277.         sViewPath = "..." & Right(sViewPath,58)
  278.     End If
  279.     CutPathView = sViewPath
  280. End Function
  281.  
  282.  
  283. ' Deletes the content of all cells that are softformatted according
  284. ' to the 'InputStyleName'
  285. Sub DeleteInputCells(oSheet as Object, InputStyleName as String)
  286. Dim oRanges as Object
  287. Dim oRange as Object
  288.     oRanges = oSheet.CellFormatRanges.createEnumeration
  289.     While oRanges.hasMoreElements
  290.         oRange = oRanges.NextElement
  291.         If Instr(1,oRange.CellStyle, InputStyleName) <> 0 Then
  292.             Call ReplaceRangeValues(oRange, "")
  293.         End If
  294.     Wend
  295. End Sub
  296.  
  297.  
  298. ' Inserts a certain String to all cells of a Range that ist passed over
  299. ' either as an object or as the RangeName
  300. Sub ChangeValueofRange(oSheet as Object, Range, ReplaceValue, Optional StyleName as String)
  301. Dim oCellRange as Object
  302.     If Vartype(Range) = 8 Then
  303.         ' Get the Range out of the Rangename
  304.         oCellRange = oSheet.GetCellRangeByName(Range)
  305.     Else
  306.         ' The range is passed over as an object
  307.         Set oCellRange = Range
  308.     End If
  309.     If IsMissing(StyleName) Then
  310.         ReplaceRangeValues(oCellRange, ReplaceValue)
  311.     Else
  312.         If Instr(1,oCellRange.CellStyle,StyleName) Then
  313.             ReplaceRangeValues(oCellRange, ReplaceValue)
  314.         End If
  315.     End If
  316. End Sub
  317.  
  318.  
  319. Sub ReplaceRangeValues(oRange as Object, ReplaceValue)
  320. Dim oRangeAddress as Object
  321. Dim ColCount as Integer
  322. Dim RowCount as Integer
  323. Dim i as Integer
  324.     oRangeAddress = oRange.RangeAddress
  325.     ColCount = oRangeAddress.EndColumn - oRangeAddress.StartColumn
  326.     RowCount = oRangeAddress.EndRow - oRangeAddress.StartRow
  327.     Dim FillArray(RowCount) as Variant
  328.     Dim sLine(ColCount) as Variant
  329.     For i = 0 To ColCount
  330.         sLine(i) = ReplaceValue
  331.     Next i
  332.     For i = 0 To RowCount
  333.         FillArray(i) = sLine()
  334.     Next i
  335.     oRange.DataArray = FillArray()
  336. End Sub
  337.  
  338.  
  339. ' Returns the Value of the first cell of a Range
  340. Function GetValueofCellbyName(oSheet as Object, sCellName as String)
  341. Dim oCell as Object
  342.     oCell = GetCellByName(oSheet, sCellName)
  343.     GetValueofCellbyName = oCell.Value
  344. End Function
  345.  
  346.  
  347. Function DuplicateRow(oSheet as Object, RangeName as String)
  348. Dim oRange as Object
  349. Dim oCell as Object
  350. Dim oCellAddress as New com.sun.star.table.CellAddress
  351. Dim oRangeAddress as New com.sun.star.table.CellRangeAddress 
  352.     oRange = oSheet.GetCellRangeByName(RangeName)
  353.     oRangeAddress = oRange.RangeAddress
  354.     oCell = oSheet.GetCellByPosition(oRangeAddress.StartColumn,oRangeAddress.StartRow)
  355.     oCellAddress = oCell.CellAddress
  356.     oSheet.Rows.InsertByIndex(oCellAddress.Row,1)
  357.     oRangeAddress = oRange.RangeAddress
  358.     oSheet.CopyRange(oCellAddress, oRangeAddress)
  359.     DuplicateRow = oRangeAddress.StartRow-1
  360. End Function
  361.  
  362.  
  363. ' Returns the String of the first cell of a Range
  364. Function GetStringofCellbyName(oSheet as Object, sCellName as String)
  365. Dim oCell as Object
  366.     oCell = GetCellByName(oSheet, sCellName)
  367.     GetStringofCellbyName = oCell.String
  368. End Function
  369.  
  370.  
  371. ' Returns a named Cell
  372. Function GetCellByName(oSheet as Object, sCellName as String) as Object
  373. Dim oCellRange as Object
  374. Dim oCellAddress as Object
  375.     oCellRange = oSheet.GetCellRangeByName(sCellName)
  376.     oCellAddress = oCellRange.RangeAddress
  377.     GetCellByName = oSheet.GetCellByPosition(oCellAddress.StartColumn,oCellAddress.StartRow)
  378. End Function
  379.  
  380.  
  381. ' Changes the numeric Value of a cell by transmitting the String of the numeric Value
  382. Sub ChangeCellValue(oCell as Object, ValueString as String)
  383. Dim CellValue
  384.     oCell.Formula = "=Value(" & """" & ValueString & """" & ")"
  385.     CellValue = oCell.Value
  386.     oCell.Formula = ""
  387.     oCell.Value = CellValue
  388. End Sub
  389.  
  390. Sub Main
  391. '    oDocument = StarDesktop.ActiveFrame.Controller.Model
  392.     oComponents = StarDesktop.Components.CreateEnumeration
  393.     Do 
  394.         oComponent = oComponents.NextElement
  395.         ShowSupportedServicenames(oComponent)    
  396.     Loop Until Not oComponents.HasMoreElements
  397.     For i = 0 To Ubound(StarDesktop.Components())
  398.         PrintdbgInfo StarDesktop.Components(i)
  399.     Next i
  400. End Sub
  401.  
  402. Function GetDocumentType(oDocument)
  403.     If oDocument.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
  404.         GetDocumentType() = "scalc"
  405.     ElseIf oDocument.SupportsService("com.sun.star.text.TextDocument") Then
  406.         GetDocumentType() = "swriter"
  407.     ElseIf oDocument.SupportsService("com.sun.star.drawing.DrawingDocument") Then
  408.         GetDocumentType() = "sdraw"
  409.     ElseIf oDocument.SupportsService("com.sun.star.formula.FormulaProperties") Then
  410.         GetDocumentType() = "smath"
  411.     End If
  412. End Function
  413.  
  414.  
  415.  
  416. Function GetNumberFormatType(oDocFormats, oFormatObject as Object) as Integer
  417. Dim ThisFormatKey as Long
  418. Dim oObjectFormat as Object
  419.     On Local Error Goto NOFORMAT
  420.     ThisFormatKey = oFormatObject.NumberFormat
  421.     oObjectFormat = oDocFormats.GetByKey(ThisFormatKey)
  422.     GetNumberFormatType = oObjectFormat.Type
  423.     NOFORMAT:
  424.     If Err <> 0 Then
  425.         Msgbox("Numberformat of Object is not available!", 16, GetProductName())
  426.         GetNumberFormatType = 0
  427.         GOTO NOERROR
  428.     End If
  429.     NOERROR:
  430.     On Local Error Goto 0
  431. End Function
  432.  
  433.  
  434. Sub ProtectSheets(Optional oSheets as Object)
  435. Dim i as Integer
  436. Dim oDocSheets as Object
  437.     If IsMissing(oSheets) Then
  438.         oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
  439.     Else
  440.         Set oDocSheets = oSheets
  441.     End If
  442.  
  443.     For i = 0 To oDocSheets.Count-1
  444.         oDocSheets(i).Protect("")
  445.     Next i
  446. End Sub
  447.  
  448.  
  449. Sub UnprotectSheets(Optional oSheets as Object)
  450. Dim i as Integer
  451. Dim oDocSheets as Object
  452.     If IsMissing(oSheets) Then
  453.         oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
  454.     Else
  455.         Set oDocSheets = oSheets
  456.     End If
  457.  
  458.     For i = 0 To oDocSheets.Count-1
  459.         oDocSheets(i).Unprotect("")
  460.     Next i
  461. End Sub
  462.  
  463.  
  464. Function GetRowIndex(oSheet as Object, RowName as String)
  465. Dim oRange as Object
  466.     oRange = oSheet.GetCellRangeByName(RowName)
  467.     GetRowIndex = oRange.RangeAddress.StartRow
  468. End Function
  469.  
  470.  
  471. Function GetColumnIndex(oSheet as Object, ColName as String)
  472. Dim oRange as Object
  473.     oRange = oSheet.GetCellRangeByName(ColName)
  474.     GetColumnIndex = oRange.RangeAddress.StartColumn
  475. End Function
  476.  
  477.  
  478. Function CopySheetbyName(oSheets as Object, OldName as String, NewName as String, DestPos as Integer) as Object
  479. Dim oSheet as Object
  480. Dim Count as Integer
  481. Dim BasicSheetName as String
  482.  
  483.     BasicSheetName = NewName
  484.     ' Copy the last table. Assumption: The last table is the template
  485.     On Local Error Goto RENAMESHEET
  486.     oSheets.CopybyName(OldName, NewName, DestPos)
  487.  
  488. RENAMESHEET:
  489.     oSheet = oSheets(DestPos)
  490.     If Err <> 0 Then
  491.         ' Test if renaming failed
  492.         Count = 2
  493.         Do While oSheet.Name <> NewName
  494.             NewName = BasicSheetName & "_" & Count
  495.             oSheet.Name = NewName
  496.             Count = Count + 1
  497.         Loop
  498.         Resume CL_ERROR
  499. CL_ERROR:
  500.     End If
  501.     CopySheetbyName = oSheet
  502. End Function
  503.  
  504.  
  505. ' Dis-or enables a Window and adjusts the mousepointer accordingly
  506. Sub ToggleWindow(bDoEnable as Boolean)
  507. Dim oWindow as Object
  508. Dim oWindowPointer as Object
  509.     oWindow = StarDesktop.CurrentFrame.ComponentWindow
  510.     oWindow.Enable = bDoEnable
  511.     oWindowPointer = CreateUnoService("com.sun.star.awt.Pointer")
  512.     If bDoEnable Then
  513.         oWindowPointer.SetType(com.sun.star.awt.SystemPointer.ARROW)
  514.     Else
  515.         oWindowPointer.SetType(com.sun.star.awt.SystemPointer.WAIT)
  516.     End If
  517.     oWindow.SetPointer(oWindowPointer)
  518. End Sub
  519.  
  520.  
  521.  
  522. Function CheckNewSheetname(oSheets as Object, Sheetname as String)
  523. Dim SpecialSignsList(32) as String
  524. Dim i as Integer
  525.     SpecialSignsList(0) = "-"
  526.     SpecialSignsList(1) = "."
  527.     SpecialSignsList(2) = "!"
  528.     SpecialSignsList(3) = "?"
  529.     SpecialSignsList(4) = "/"
  530.     SpecialSignsList(5) = "\"
  531.     SpecialSignsList(6) = ","
  532.     SpecialSignsList(7) = ";"
  533.     SpecialSignsList(8) = "'"
  534.     SpecialSignsList(9) = "("
  535.     SpecialSignsList(10) = ")"
  536.     SpecialSignsList(11) = "{"
  537.     SpecialSignsList(12) = "}"
  538.     SpecialSignsList(13) = "["
  539.     SpecialSignsList(14) = "]"
  540.     SpecialSignsList(15) = ":"
  541.     SpecialSignsList(16) = """"
  542.     SpecialSignsList(17) = "$"
  543.     SpecialSignsList(18) = "&"
  544.     SpecialSignsList(19) = "%"
  545.     SpecialSignsList(20) = "="
  546.     SpecialSignsList(21) = "*"
  547.     SpecialSignsList(22) = "?├é┬º"
  548.     SpecialSignsList(23) = "@"
  549.     SpecialSignsList(24) = "<"
  550.     SpecialSignsList(25) = ">"
  551.     SpecialSignsList(26) = "#"
  552.     SpecialSignsList(27) = "+"
  553.     SpecialSignsList(28) = "~"
  554.     SpecialSignsList(29) = "|"
  555.     SpecialSignsList(30) = "??"
  556.     SpecialSignsList(31) = "^"
  557.     SpecialSignsList(32) = "?├é┬░"
  558.     For i = 0 To Ubound(SpecialSignsList())
  559.         SheetName = ReplaceString(Sheetname, "_", SpecialSignsList(i)
  560.     Next i
  561.     CheckNewSheetname = SheetName
  562. End Function
  563.  
  564.  
  565. Function GetSheetIndex(oSheets, sName) as Integer
  566. Dim i as Integer    
  567.     For i = 0 To oSheets.Count-1
  568.         If oSheets(i).Name = sName Then
  569.             GetSheetIndex = i
  570.             exit Function
  571.         End If
  572.     Next i
  573.     GetSheetIndex = -1
  574. End Function
  575.  
  576.  
  577. Function GetLastUsedRow(oSheet as Object) as Integer
  578. Dim oCell As Object
  579. Dim oCursor As Object
  580. Dim aAddress As Variant
  581.     oCell = oSheet.GetCellbyPosition(0, 0)
  582.     oCursor = oSheet.createCursorByRange(oCell)
  583.     oCursor.GotoEndOfUsedArea(True)
  584.     aAddress = oCursor.RangeAddress
  585.     GetLastUsedRow = aAddress.EndRow
  586. End Function        
  587.  
  588.  
  589. ' Note To set a one lined frame you have to set the inner width to 0
  590. ' In the API all Units that refer to pt-Heights are "1/100mm"
  591. ' The convert factor from 1pt to 1/100 mm is approximately 35
  592. Function ModifyBorderLineWidth(ByVal oStyleBorder, iInnerLineWidth as Integer, iOuterLineWidth as Integer)
  593. Dim aBorder as New com.sun.star.table.BorderLine
  594.     aBorder = oStyleBorder
  595.     aBorder.InnerLineWidth = iInnerLineWidth
  596.     aBorder.OuterLineWidth = iOuterLineWidth
  597.     ModifyBorderLineWidth = aBorder
  598. End Function
  599.  
  600.  
  601. Sub AttachBasicMacroToEvent(oDocument as Object, EventName as String, SubPath as String)
  602. Dim PropValue(1) as new com.sun.star.beans.PropertyValue
  603.     PropValue(0).Name = "EventType"
  604.     PropValue(0).Value = "StarBasic"
  605.     PropValue(1).Name = "Script"
  606.     PropValue(1).Value = "macro:///" & SubPath
  607.     oDocument.Events.ReplaceByName(EventName, PropValue())
  608. End Sub
  609.  
  610.  
  611.  
  612. Function ModifyPropertyValue(oContent() as Object, TargetProperties() as New com.sun.star.beans.PropertyValue )
  613. Dim MaxIndex as Integer
  614. Dim i as Integer
  615. Dim a as Integer
  616. Dim bDoReplace as Boolean
  617.     MaxIndex = Ubound(oContent())
  618.     bDoReplace = False
  619.     Dim oNewBuffer(MaxIndex) as New com.sun.star.beans.PropertyValue
  620.     For i = 0 To MaxIndex
  621.         oNewBuffer(i).Name = oContent(i).Name
  622.         a = GetPropertyValueIndex(oContent(i).Name, TargetProperties())
  623.         If a <> -1 Then
  624.             If Vartype(TargetProperties(a).Value) <> 9 Then
  625.                 If TargetProperties(a).Value <> oContent(i).Value Then
  626.                     oNewBuffer(i).Value = TargetProperties(a).Value
  627.                     bDoReplace = True
  628.                 Else
  629.                     oNewBuffer(i).Value = oContent(i).Value            
  630.                 End If
  631.             Else
  632.                 If Not equalUnoObjects(TargetProperties(a).Value, oContent(i).Value) Then
  633.                     oNewBuffer(i).Value = TargetProperties(a).Value
  634.                     bDoReplace = True
  635.                 Else
  636.                     oNewBuffer(i).Value = oContent(i).Value        
  637.                 End If
  638.             End If
  639.         Else
  640.             oNewBuffer(i).Value = oContent(i).Value
  641.         End If
  642.     Next i
  643.     If bDoReplace Then
  644.         oContent() = oNewBuffer()
  645.     End If
  646.     ModifyPropertyValue() = bDoReplace
  647. End Function
  648.  
  649.  
  650. Function GetPropertyValueIndex(SearchName as String, TargetProperties() as New com.sun.star.beans.PropertyValue )
  651. Dim i as Integer
  652.     For i = 0 To Ubound(TargetProperties())
  653.         If Searchname = TargetProperties(i).Name Then
  654.             GetPropertyValueIndex = i
  655.             Exit Function
  656.         End If
  657.     Next i    
  658.     GetPropertyValueIndex() = -1
  659. End Function
  660.  
  661.  
  662. Sub DispatchSlot(SlotID as Integer)
  663. Dim oArg() as new com.sun.star.beans.PropertyValue
  664. Dim oUrl as new com.sun.star.util.URL
  665. Dim oTrans as Object
  666. Dim oDisp as Object
  667.     oTrans = createUNOService("com.sun.star.util.URLTransformer")
  668.     oUrl.Complete = "slot:" & CStr(SlotID)
  669.     oTrans.parsestrict(oUrl)
  670.  
  671.     oDisp = StarDesktop.currentFrame.queryDispatch(oUrl, "_self", 0)    
  672.     oDisp.dispatch(oUrl, oArg())
  673. End Sub
  674.  
  675.  
  676. 'returns the type of the office application
  677. 'FatOffice = 0, WebTop = 1
  678. 'This routine has to be changed if the Product Name is being changed!
  679. Function IsFatOffice() As Boolean
  680.   If sProductname = "" Then
  681.     sProductname = GetProductname()
  682.   End If
  683.   IsFatOffice = TRUE
  684.   'The following line has to include the current productname
  685.   If Instr(1,sProductname,"WebTop",1) <> 0 Then
  686.     IsFatOffice = FALSE
  687.   End If
  688. End Function
  689.  
  690.  
  691. Function GetLocale(sLanguage as String, sCountry as String)
  692. Dim oLocale as New com.sun.star.lang.Locale
  693.     oLocale.Language = sLanguage
  694.     oLocale.Country = sCountry
  695.     GetLocale = oLocale
  696. End Function                    
  697.  
  698.  
  699. Sub ToggleDesignMode(oDocument as Object)
  700. Dim aSwitchMode as new com.sun.star.util.URL
  701.     aSwitchMode.Complete = ".uno:SwitchControlDesignMode"
  702.     aTransformer = createUnoService("com.sun.star.util.URLTransformer")
  703.     aTransformer.parseStrict(aSwitchMode)
  704.     oFrame = oDocument.currentController.Frame
  705.     oDispatch = oFrame.queryDispatch(aSwitchMode, oFrame.Name, 63)
  706.     Dim aEmptyArgs() as com.sun.star.bean.PropertyValue
  707.     oDispatch.dispatch(aSwitchMode, aEmptyArgs())
  708.     Erase aSwitchMode
  709. End Sub</script:module>