1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Misc" script:language="StarBasic">REM ***** BASIC *****
Const SBSHARE = 0
Const SBUSER = 1
Dim Taskindex as Integer
Dim oResSrv as Object
Sub Main()
Dim PropList(3,1)' as String
PropList(0,0) = "URL"
PropList(0,1) = "sdbc:odbc:Erica_Test_Unicode"
PropList(1,0) = "User"
PropList(1,1) = "extra"
PropList(2,0) = "Password"
PropList(2,1) = "extra"
PropList(3,0) = "IsPasswordRequired"
PropList(3,1) = True
End Sub
Function RegisterNewDataSource(DSName as String, PropertyList(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue)
Dim oDataSource as Object
Dim oDBContext as Object
Dim oPropInfo as Object
Dim i as Integer
oDBContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oDataSource = createUnoService("com.sun.star.sdb.DataSource")
For i = 0 To Ubound(PropertyList(), 1)
sPropName = PropertyList(i,0)
sPropValue = PropertyList(i,1)
oDataSource.SetPropertyValue(sPropName,sPropValue)
Next i
If Not IsMissing(DriverProperties()) Then
oDataSource.Info() = DriverProperties()
End If
oDBContext.RegisterObject(DSName, oDataSource)
RegisterNewDataSource () = oDataSource
End Function
' Connects to a registered Database
Function ConnecttoDatabase(DSName as String, UserID as String, Password as String, Optional Propertylist(), Optional DriverProperties() as New com.sun.star.beans.PropertyValue)
Dim oDBContext as Object
Dim oDBSource as Object
' On Local Error Goto NOCONNECTION
oDBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
If oDBContext.HasbyName(DSName) Then
oDBSource = oDBContext.GetByName(DSName)
ConnectToDatabase = oDBSource.GetConnection(UserID, Password)
Else
If Not IsMissing(Namelist()) Then
If Not IsMissing(DriverProperties()) Then
RegisterNewDataSource(DSName, PropertyList(), DriverProperties())
Else
RegisterNewDataSource(DSName, PropertyList())
End If
oDBSource = oDBContext.GetByName(DSName)
ConnectToDatabase = oDBSource.GetConnection(UserID, Password)
Else
Msgbox("DataSource " & DSName & " is not registered" , 16, GetProductname())
ConnectToDatabase() = NULL
End If
End If
NOCONNECTION:
If Err <> 0 Then
Msgbox(Error$, 16, GetProductName())
Resume LEAVESUB
LEAVESUB:
End If
End Function
Function GetStarOfficeLocale() as New com.sun.star.lang.Locale
Dim aLocLocale As New com.sun.star.lang.Locale
Dim sLocale as String
Dim sLocaleList(1)
Dim oMasterKey
oMasterKey = GetRegistryKeyContent("org.openoffice.Setup/L10N/")
sLocale = oMasterKey.getByName("ooLocale")
sLocaleList() = ArrayoutofString(sLocale, "-")
aLocLocale.Language = sLocaleList(0)
If Ubound(sLocaleList()) > 0 Then
aLocLocale.Country = sLocaleList(1)
End If
If Ubound(sLocaleList()) > 1 Then
aLocLocale.Variant = sLocaleList(2)
End If
GetStarOfficeLocale() = aLocLocale
End Function
Function GetRegistryKeyContent(sKeyName as string, Optional bforUpdate as Boolean)
Dim oConfigProvider as Object
Dim aNodePath(0) as new com.sun.star.beans.PropertyValue
oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
aNodePath(0).Name = "nodepath"
aNodePath(0).Value = sKeyName
If IsMissing(bForUpdate) Then
GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath())
Else
If bForUpdate Then
GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aNodePath())
Else
GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath())
End If
End If
End Function
Function GetProductname() as String
Dim oProdNameAccess as Object
Dim sVersion as String
Dim sProdName as String
oProdNameAccess = GetRegistryKeyContent("org.openoffice.Setup/Product")
sProdName = oProdNameAccess.getByName("ooName")
sVersion = oProdNameAccess.getByName("ooSetupVersion")
GetProductName = sProdName & sVersion
End Function
' Opens a Document, checks beforehand, whether it has to be loaded
' or whether it is already on the desktop.
' If the parameter bDisposable is set to False then the returned document
' should not be disposed afterwards, because it is already opened.
Function OpenDocument(DocPath as String, Args(), Optional bDisposable as Boolean)
Dim oComponents as Object
Dim oComponent as Object
' Search if one of the active Components is the one that you search for
oComponents = StarDesktop.Components.CreateEnumeration
While oComponents.HasmoreElements
oComponent = oComponents.NextElement
If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") then
If UCase(oComponent.URL) = UCase(DocPath) then
OpenDocument() = oComponent
If Not IsMissing(bDisposable) Then
bDisposable = False
End If
Exit Function
End If
End If
Wend
If Not IsMissing(bDisposable) Then
bDisposable = True
End If
OpenDocument() = StarDesktop.LoadComponentFromURL(DocPath,"_default",0,Args())
End Function
Function TaskonDesktop(DocPath as String) as Boolean
Dim oComponents as Object
Dim oComponent as Object
' Search if one of the active Components is the one that you search for
oComponents = StarDesktop.Components.CreateEnumeration
While oComponents.HasmoreElements
oComponent = oComponents.NextElement
If hasUnoInterfaces(oComponent,"com.sun.star.frame.XModel") then
If UCase(oComponent.URL) = UCase(DocPath) then
TaskonDesktop = True
Exit Function
End If
End If
Wend
TaskonDesktop = False
End Function
' Retrieves a FileName out of a StarOffice-Document
Function RetrieveFileName(LocDoc as Object)
Dim LocURL as String
Dim LocURLArray() as String
Dim MaxArrIndex as integer
LocURL = LocDoc.Url
LocURLArray() = ArrayoutofString(LocURL,"/",MaxArrIndex)
RetrieveFileName = LocURLArray(MaxArrIndex)
End Function
' Gets a special configured PathSetting
Function GetPathSettings(sPathType as String, Optional bshowall as Boolean, Optional ListIndex as integer) as String
Dim oSettings, oPathSettings as Object
Dim sPath as String
Dim PathList() as String
Dim MaxIndex as Integer
Dim oPS as Object
oPS = createUnoService("com.sun.star.util.PathSettings")
If Not IsMissing(bShowall) Then
If bShowAll Then
ShowPropertyValues(oPS)
Exit Function
End If
End If
sPath = oPS.getPropertyValue(sPathType)
If Not IsMissing(ListIndex) Then
' Share and User-Directory
If Instr(1,sPath,";") <> 0 Then
PathList = ArrayoutofString(sPath,";", MaxIndex)
If ListIndex <= MaxIndex Then
sPath = PathList(ListIndex)
Else
Msgbox("String Cannot be analyzed!" & sPath , 16, GetProductName())
End If
End If
End If
If Instr(1, sPath, ";") = 0 Then
GetPathSettings = ConvertToUrl(sPath)
Else
GetPathSettings = sPath
End If
End Function
' Gets the fully qualified path to a subdirectory of the
' Template Directory, e. g. with the parameter "wizard/bitmap"
' The parameter must be passed in Url notation
' The return-Value is in Url notation
Function GetOfficeSubPath(sOfficePath as String, ByVal sSubDir as String)
Dim sOfficeString as String
Dim sOfficeList() as String
Dim sOfficeDir as String
Dim sBigDir as String
Dim i as Integer
Dim MaxIndex as Integer
Dim oUcb as Object
oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
sOfficeString = GetPathSettings(sOfficePath)
If Right(sSubDir,1) <> "/" Then
sSubDir = sSubDir & "/"
End If
sOfficeList() = ArrayoutofString(sOfficeString,";", MaxIndex)
For i = 0 To MaxIndex
sOfficeDir = ConvertToUrl(sOfficeList(i))
If Right(sOfficeDir,1) <> "/" Then
sOfficeDir = sOfficeDir & "/"
End If
sBigDir = sOfficeDir & sSubDir
If oUcb.Exists(sBigDir) Then
GetOfficeSubPath() = sBigDir
Exit Function
End If
Next i
ShowNoOfficePathError()
GetOfficeSubPath = ""
End Function
Sub ShowNoOfficePathError()
Dim ProductName as String
Dim sError as String
Dim bResObjectexists as Boolean
Dim oLocResSrv as Object
bResObjectexists = not IsNull(oResSrv)
If bResObjectexists Then
oLocResSrv = oResSrv
End If
If InitResources("Tools") Then
ProductName = GetProductName()
sError = GetResText("RID_COMMON_6")
sError = ReplaceString(sError, ProductName, "%PRODUCTNAME")
sError = ReplaceString(sError, chr(13), "<BR>")
MsgBox(sError, 16, ProductName)
End If
If bResObjectexists Then
oResSrv = oLocResSrv
End If
End Sub
Function InitResources(Description) as boolean
Dim xResource as Object
Dim sOfficeDir as String
Dim aArgs(5) as Any
On Error Goto ErrorOcurred
sOfficeDir = "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/wizards/"
sOfficeDir = GetDefaultContext.getByName("/singletons/com.sun.star.util.theMacroExpander").ExpandMacros(sOfficeDir)
aArgs(0) = sOfficeDir
aArgs(1) = true
aArgs(2) = GetStarOfficeLocale()
aArgs(3) = "resources"
aArgs(4) = ""
aArgs(5) = NULL
oResSrv = getProcessServiceManager().createInstanceWithArguments( "com.sun.star.resource.StringResourceWithLocation", aArgs() )
If (IsNull(oResSrv)) then
InitResources = FALSE
MsgBox("could not initialize StringResourceWithLocation")
Else
InitResources = TRUE
End If
Exit Function
ErrorOcurred:
Dim nSolarVer
InitResources = FALSE
nSolarVer = GetSolarVersion()
MsgBox("Resource file missing", 16, GetProductName())
Resume CLERROR
CLERROR:
End Function
Function GetResText( sID as String ) As string
Dim sString as String
On Error Goto ErrorOcurred
If Not IsNull(oResSrv) Then
sString = oResSrv.resolveString(sID)
GetResText = ReplaceString(sString, GetProductname(), "%PRODUCTNAME")
Else
GetResText = ""
End If
Exit Function
ErrorOcurred:
GetResText = ""
MsgBox("Resource with ID =" + sID + " not found!", 16, GetProductName())
Resume CLERROR
CLERROR:
End Function
Function CutPathView(sDocUrl as String, Optional PathLen as Integer)
Dim sViewPath as String
Dim FileName as String
Dim iFileLen as Integer
sViewPath = ConvertfromURL(sDocURL)
iViewPathLen = Len(sViewPath)
If iViewPathLen > 60 Then
FileName = FileNameoutofPath(sViewPath, "/")
iFileLen = Len(FileName)
If iFileLen < 44 Then
sViewPath = Left(sViewPath,57-iFileLen-10) & "..." & Right(sViewPath,iFileLen + 10)
Else
sViewPath = Left(sViewPath,27) & " ... " & Right(sViewPath,28)
End If
End If
CutPathView = sViewPath
End Function
' Deletes the content of all cells that are softformatted according
' to the 'InputStyleName'
Sub DeleteInputCells(oSheet as Object, InputStyleName as String)
Dim oRanges as Object
Dim oRange as Object
oRanges = oSheet.CellFormatRanges.createEnumeration
While oRanges.hasMoreElements
oRange = oRanges.NextElement
If Instr(1,oRange.CellStyle, InputStyleName) <> 0 Then
Call ReplaceRangeValues(oRange, "")
End If
Wend
End Sub
' Inserts a certain string to all cells of a range that is passed
' either as an object or as the RangeName
Sub ChangeValueofRange(oSheet as Object, Range, ReplaceValue, Optional StyleName as String)
Dim oCellRange as Object
If Vartype(Range) = 8 Then
' Get the Range out of the Rangename
oCellRange = oSheet.GetCellRangeByName(Range)
Else
' The range is passed as an object
Set oCellRange = Range
End If
If IsMissing(StyleName) Then
ReplaceRangeValues(oCellRange, ReplaceValue)
Else
If Instr(1,oCellRange.CellStyle,StyleName) Then
ReplaceRangeValues(oCellRange, ReplaceValue)
End If
End If
End Sub
Sub ReplaceRangeValues(oRange as Object, ReplaceValue)
Dim oRangeAddress as Object
Dim ColCount as Integer
Dim RowCount as Integer
Dim i as Integer
oRangeAddress = oRange.RangeAddress
ColCount = oRangeAddress.EndColumn - oRangeAddress.StartColumn
RowCount = oRangeAddress.EndRow - oRangeAddress.StartRow
Dim FillArray(RowCount) as Variant
Dim sLine(ColCount) as Variant
For i = 0 To ColCount
sLine(i) = ReplaceValue
Next i
For i = 0 To RowCount
FillArray(i) = sLine()
Next i
oRange.DataArray = FillArray()
End Sub
' Returns the Value of the first cell of a Range
Function GetValueofCellbyName(oSheet as Object, sCellName as String)
Dim oCell as Object
oCell = GetCellByName(oSheet, sCellName)
GetValueofCellbyName = oCell.Value
End Function
Function DuplicateRow(oSheet as Object, RangeName as String)
Dim oRange as Object
Dim oCell as Object
Dim oCellAddress as New com.sun.star.table.CellAddress
Dim oRangeAddress as New com.sun.star.table.CellRangeAddress
oRange = oSheet.GetCellRangeByName(RangeName)
oRangeAddress = oRange.RangeAddress
oCell = oSheet.GetCellByPosition(oRangeAddress.StartColumn,oRangeAddress.StartRow)
oCellAddress = oCell.CellAddress
oSheet.Rows.InsertByIndex(oCellAddress.Row,1)
oRangeAddress = oRange.RangeAddress
oSheet.CopyRange(oCellAddress, oRangeAddress)
DuplicateRow = oRangeAddress.StartRow-1
End Function
' Returns the String of the first cell of a Range
Function GetStringofCellbyName(oSheet as Object, sCellName as String)
Dim oCell as Object
oCell = GetCellByName(oSheet, sCellName)
GetStringofCellbyName = oCell.String
End Function
' Returns a named Cell
Function GetCellByName(oSheet as Object, sCellName as String) as Object
Dim oCellRange as Object
Dim oCellAddress as Object
oCellRange = oSheet.GetCellRangeByName(sCellName)
oCellAddress = oCellRange.RangeAddress
GetCellByName = oSheet.GetCellByPosition(oCellAddress.StartColumn,oCellAddress.StartRow)
End Function
' Changes the numeric Value of a cell by transmitting the String of the numeric Value
Sub ChangeCellValue(oCell as Object, ValueString as String)
Dim CellValue
oCell.Formula = "=Value(" & """" & ValueString & """" & ")"
CellValue = oCell.Value
oCell.Formula = ""
oCell.Value = CellValue
End Sub
Function GetDocumentType(oDocument)
On Local Error GoTo NODOCUMENTTYPE
' ShowSupportedServiceNames(oDocument)
If oDocument.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
GetDocumentType() = "scalc"
ElseIf oDocument.SupportsService("com.sun.star.text.TextDocument") Then
GetDocumentType() = "swriter"
ElseIf oDocument.SupportsService("com.sun.star.drawing.DrawingDocument") Then
GetDocumentType() = "sdraw"
ElseIf oDocument.SupportsService("com.sun.star.presentation.PresentationDocument") Then
GetDocumentType() = "simpress"
ElseIf oDocument.SupportsService("com.sun.star.formula.FormulaProperties") Then
GetDocumentType() = "smath"
End If
NODOCUMENTTYPE:
If Err <> 0 Then
GetDocumentType = ""
Resume GOON
GOON:
End If
End Function
Function GetNumberFormatType(oDocFormats, oFormatObject as Object) as Integer
Dim ThisFormatKey as Long
Dim oObjectFormat as Object
On Local Error Goto NOFORMAT
ThisFormatKey = oFormatObject.NumberFormat
oObjectFormat = oDocFormats.GetByKey(ThisFormatKey)
GetNumberFormatType = oObjectFormat.Type
NOFORMAT:
If Err <> 0 Then
Msgbox("Numberformat of Object is not available!", 16, GetProductName())
GetNumberFormatType = 0
GOTO NOERROR
End If
NOERROR:
On Local Error Goto 0
End Function
Sub ProtectSheets(Optional oSheets as Object)
Dim i as Integer
Dim oDocSheets as Object
If IsMissing(oSheets) Then
oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
Else
Set oDocSheets = oSheets
End If
For i = 0 To oDocSheets.Count-1
oDocSheets(i).Protect("")
Next i
End Sub
Sub UnprotectSheets(Optional oSheets as Object)
Dim i as Integer
Dim oDocSheets as Object
If IsMissing(oSheets) Then
oDocSheets = StarDesktop.CurrentFrame.Controller.Model.Sheets
Else
Set oDocSheets = oSheets
End If
For i = 0 To oDocSheets.Count-1
oDocSheets(i).Unprotect("")
Next i
End Sub
Function GetRowIndex(oSheet as Object, RowName as String)
Dim oRange as Object
oRange = oSheet.GetCellRangeByName(RowName)
GetRowIndex = oRange.RangeAddress.StartRow
End Function
Function GetColumnIndex(oSheet as Object, ColName as String)
Dim oRange as Object
oRange = oSheet.GetCellRangeByName(ColName)
GetColumnIndex = oRange.RangeAddress.StartColumn
End Function
Function CopySheetbyName(oSheets as Object, OldName as String, NewName as String, DestPos as Integer) as Object
Dim oSheet as Object
Dim Count as Integer
Dim BasicSheetName as String
BasicSheetName = NewName
' Copy the last table. Assumption: The last table is the template
On Local Error Goto RENAMESHEET
oSheets.CopybyName(OldName, NewName, DestPos)
RENAMESHEET:
oSheet = oSheets(DestPos)
If Err <> 0 Then
' Test if renaming failed
Count = 2
Do While oSheet.Name <> NewName
NewName = BasicSheetName & "_" & Count
oSheet.Name = NewName
Count = Count + 1
Loop
Resume CL_ERROR
CL_ERROR:
End If
CopySheetbyName = oSheet
End Function
' Dis-or enables a Window and adjusts the mousepointer accordingly
Sub ToggleWindow(bDoEnable as Boolean)
Dim oWindow as Object
oWindow = StarDesktop.CurrentFrame.ComponentWindow
oWindow.Enable = bDoEnable
End Sub
Function CheckNewSheetname(oSheets as Object, Sheetname as String, Optional oLocale) as String
Dim nStartFlags as Long
Dim nContFlags as Long
Dim oCharService as Object
Dim iSheetNameLength as Integer
Dim iResultPos as Integer
Dim WrongChar as String
Dim oResult as Object
nStartFlags = com.sun.star.i18n.KParseTokens.ANY_LETTER_OR_NUMBER + com.sun.star.i18n.KParseTokens.ASC_UNDERSCORE
nContFlags = nStartFlags
oCharService = CreateUnoService("com.sun.star.i18n.CharacterClassification")
iSheetNameLength = Len(SheetName)
If IsMissing(oLocale) Then
oLocale = ThisComponent.CharLocale
End If
Do
oResult =oCharService.parsePredefinedToken(com.sun.star.i18n.KParseType.IDENTNAME, SheetName, 0, oLocale, nStartFlags, "", nContFlags, " ")
iResultPos = oResult.EndPos
If iResultPos < iSheetNameLength Then
WrongChar = Mid(SheetName, iResultPos+1,1)
SheetName = ReplaceString(SheetName,"_", WrongChar)
End If
Loop Until iResultPos = iSheetNameLength
CheckNewSheetname = SheetName
End Function
Sub AddNewSheetName(oSheets as Object, ByVal SheetName as String)
Dim Count as Integer
Dim bSheetIsThere as Boolean
Dim iSheetNameLength as Integer
iSheetNameLength = Len(SheetName)
Count = 2
Do
bSheetIsThere = oSheets.HasByName(SheetName)
If bSheetIsThere Then
SheetName = Right(SheetName,iSheetNameLength) & "_" & Count
Count = Count + 1
End If
Loop Until Not bSheetIsThere
AddNewSheetname = SheetName
End Sub
Function GetSheetIndex(oSheets, sName) as Integer
Dim i as Integer
For i = 0 To oSheets.Count-1
If oSheets(i).Name = sName Then
GetSheetIndex = i
exit Function
End If
Next i
GetSheetIndex = -1
End Function
Function GetLastUsedRow(oSheet as Object) as Long
Dim oCell As Object
Dim oCursor As Object
Dim aAddress As Variant
oCell = oSheet.GetCellbyPosition(0, 0)
oCursor = oSheet.createCursorByRange(oCell)
oCursor.GotoEndOfUsedArea(True)
aAddress = oCursor.RangeAddress
GetLastUsedRow = aAddress.EndRow
End Function
' Note To set a one lined frame you have to set the inner width to 0
' In the API all Units that refer to pt-Heights are "1/100mm"
' The convert factor from 1pt to 1/100 mm is approximately 35
Function ModifyBorderLineWidth(ByVal oStyleBorder, iInnerLineWidth as Integer, iOuterLineWidth as Integer)
Dim aBorder as New com.sun.star.table.BorderLine
aBorder = oStyleBorder
aBorder.InnerLineWidth = iInnerLineWidth
aBorder.OuterLineWidth = iOuterLineWidth
ModifyBorderLineWidth = aBorder
End Function
Sub AttachBasicMacroToEvent(oDocument as Object, EventName as String, SubPath as String)
Dim PropValue(1) as new com.sun.star.beans.PropertyValue
PropValue(0).Name = "EventType"
PropValue(0).Value = "StarBasic"
PropValue(1).Name = "Script"
PropValue(1).Value = "macro:///" & SubPath
oDocument.Events.ReplaceByName(EventName, PropValue())
End Sub
Function ModifyPropertyValue(oContent() as New com.sun.star.beans.PropertyValue, TargetProperties() as New com.sun.star.beans.PropertyValue)
Dim MaxIndex as Integer
Dim i as Integer
Dim a as Integer
MaxIndex = Ubound(oContent())
bDoReplace = False
For i = 0 To MaxIndex
a = GetPropertyValueIndex(oContent(i).Name, TargetProperties())
If a <> -1 Then
If Vartype(TargetProperties(a).Value) <> 9 Then
If TargetProperties(a).Value <> oContent(i).Value Then
oContent(i).Value = TargetProperties(a).Value
bDoReplace = True
End If
Else
If Not EqualUnoObjects(TargetProperties(a).Value, oContent(i).Value) Then
oContent(i).Value = TargetProperties(a).Value
bDoReplace = True
End If
End If
End If
Next i
ModifyPropertyValue() = bDoReplace
End Function
Function GetPropertyValueIndex(SearchName as String, TargetProperties() as New com.sun.star.beans.PropertyValue ) as Integer
Dim i as Integer
For i = 0 To Ubound(TargetProperties())
If Searchname = TargetProperties(i).Name Then
GetPropertyValueIndex = i
Exit Function
End If
Next i
GetPropertyValueIndex() = -1
End Function
Sub DispatchSlot(SlotID as Integer)
Dim oArg() as new com.sun.star.beans.PropertyValue
Dim oUrl as new com.sun.star.util.URL
Dim oTrans as Object
Dim oDisp as Object
oTrans = createUNOService("com.sun.star.util.URLTransformer")
oUrl.Complete = "slot:" & CStr(SlotID)
oTrans.parsestrict(oUrl)
oDisp = StarDesktop.ActiveFrame.queryDispatch(oUrl, "_self", 0)
oDisp.dispatch(oUrl, oArg())
End Sub
'returns the type of the office application
'FatOffice = 0, WebTop = 1
'This routine has to be changed if the Product Name is being changed!
Function IsFatOffice() As Boolean
If sProductname = "" Then
sProductname = GetProductname()
End If
IsFatOffice = TRUE
'The following line has to include the current productname
If Instr(1,sProductname,"WebTop",1) <> 0 Then
IsFatOffice = FALSE
End If
End Function
Sub ToggleDesignMode(oDocument as Object)
Dim aSwitchMode as new com.sun.star.util.URL
aSwitchMode.Complete = ".uno:SwitchControlDesignMode"
aTransformer = createUnoService("com.sun.star.util.URLTransformer")
aTransformer.parseStrict(aSwitchMode)
oFrame = oDocument.currentController.Frame
oDispatch = oFrame.queryDispatch(aSwitchMode, oFrame.Name, 63)
Dim aEmptyArgs() as New com.sun.star.bean.PropertyValue
oDispatch.dispatch(aSwitchMode, aEmptyArgs())
Erase aSwitchMode
End Sub
Function isHighContrast(oPeer as Object)
Dim UIColor as Long
Dim myRed as Integer
Dim myGreen as Integer
Dim myBlue as Integer
Dim myLuminance as Double
UIColor = oPeer.getProperty( "DisplayBackgroundColor" )
myRed = Red (UIColor)
myGreen = Green (UIColor)
myBlue = Blue (UIColor)
myLuminance = (( myBlue*28 + myGreen*151 + myRed*77 ) / 256 )
isHighContrast = false
If myLuminance <= 25 Then isHighContrast = true
End Function
Function CreateNewDocument(sType as String, Optional sAddMsg as String) as Object
Dim NoArgs() as new com.sun.star.beans.PropertyValue
Dim oDocument as Object
Dim sUrl as String
Dim ErrMsg as String
On Local Error Goto NOMODULEINSTALLED
sUrl = "private:factory/" & sType
oDocument = StarDesktop.LoadComponentFromURL(sUrl,"_default",0, NoArgs())
NOMODULEINSTALLED:
If (Err <> 0) OR IsNull(oDocument) Then
If InitResources("") Then
Select Case sType
Case "swriter"
ErrMsg = GetResText("RID_COMMON_1")
Case "scalc"
ErrMsg = GetResText("RID_COMMON_2")
Case "simpress"
ErrMsg = GetResText("RID_COMMON_3")
Case "sdraw"
ErrMsg = GetResText("RID_COMMON_4")
Case "smath"
ErrMsg = GetResText("RID_COMMON_5")
Case Else
ErrMsg = "Invalid Document Type!"
End Select
ErrMsg = ReplaceString(ErrMsg, chr(13), "<BR>")
If Not IsMissing(sAddMsg) Then
ErrMsg = ErrMsg & chr(13) & sAddMsg
End If
Msgbox(ErrMsg, 48, GetProductName())
End If
If Err <> 0 Then
Resume GOON
End If
End If
GOON:
CreateNewDocument = oDocument
End Function
' This Sub has been used in order to ensure that after disposing a document
' from the backing window it is returned to the backing window, so the
' office won't be closed
Sub DisposeDocument(oDocument as Object)
Dim dispatcher as Object
Dim parser as Object
Dim disp as Object
Dim url as new com.sun.star.util.URL
Dim NoArgs() as New com.sun.star.beans.PropertyValue
Dim oFrame as Object
If Not IsNull(oDocument) Then
oDocument.setModified(false)
parser = createUnoService("com.sun.star.util.URLTransformer")
url.Complete = ".uno:CloseDoc"
parser.parseStrict(url)
oFrame = oDocument.CurrentController.Frame
disp = oFrame.queryDispatch(url,"_self", com.sun.star.util.SearchFlags.NORM_WORD_ONLY)
disp.dispatch(url, NoArgs())
End If
End Sub
'Function to calculate if the year is a leap year
Function CalIsLeapYear(ByVal iYear as Integer) as Boolean
CalIsLeapYear = ((iYear Mod 4 = 0) And ((iYear Mod 100 <> 0) Or (iYear Mod 400 = 0)))
End Function
</script:module>
|