OpenOffice Basic

来源:互联网 发布:怎么得到知乎live礼券 编辑:程序博客网 时间:2024/05/18 02:29

How to find/replace with hyperlinks in Writer 怎样获取超链接

sub markHyperlink
dim oParaEnum as object
dim oPortEnum as object
dim oPara as object
dim oPort as object

oParaEnum = thisComponent.text.createEnumeration()

do while oParaEnum.hasMoreElements()
oPara = oParaEnum.nextElement

if oPara.supportsService("com.sun.star.text.Paragraph") then
rem if you're sure you'll never use a table for whatever reason, you can get rid of this if clause
oPortEnum = oPara.createEnumeration

do while oPortEnum.hasMoreElements()
oPort = oPortEnum.nextElement()

if isHyperlink(oPort) then
rem please note that 'isHyperlink()' is a stand in for however you end up determining whether something is a hyperlink
thisComponent.text.insertString(oPort.getStart(), ">>", false)
endif

loop
endif
loop

end sub

function isHyperlink(oTextPortion as object) as boolean
with oTextPortion
if .hyperlinkTarget = "" and .hyperlinkName = "" and .hyperlinkURL = "" then
isHyperlink = false
else
isHyperlink = true
endif
end with
end function

How to output string to file with Star Basic

input1 =  text.dbg_methods
n = FreeFile                    'Always find the next free file number
FileName = ConvertToURL(CurDir) & "/delme.txt"
Open FileName For Output As #n
Write #n, input1
close #n

How to modify the border of texttable in openoffice word processing

Sub Main
'   oDoc = ThisComponent
   oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array()
   ' Create a table
   oTable = oDoc.createInstance( "com.sun.star.text.TextTable" )
   ' Initialise table to have seven rows, five columns
   oTable.initialize( 7, 5 )
   ' Get view cursor
   oViewCursor = oDoc.getCurrentController().getViewCursor()
   ' Get text of the document.
   oText = oDoc.getText()
   'Insert table into text at current view cursor position.
   oText.insertTextContent( oViewCursor, oTable, False )
   ' Now let's have some fun with the table.
   ' Fill in all the cells.
   For nRow = 0 To oTable.getRows().getCount() - 1
      For nCol = 0 To oTable.getColumns().getCount() - 1
         oCell = oTable.getCellByPosition( nCol, nRow )
         ' Get the cell's text.
         oText = oCell.getText()
         ' Get a cursor on the cell's text.
         oCursor = oText.createTextCursor()
         ' Insert something random
         oText.insertString( oCursor, "$"+CSTR( Int( Rnd() * 10000 ) ), False )
         ' For some rows, make the number format be Currency.
         If nRow <= 3 Then
            oCell.NumberFormat = com.sun.star.util.NumberFormat.CURRENCY
         Else
            oCell.NumberFormat = com.sun.star.util.NumberFormat.TEXT
         EndIf
         oCell.LeftBorder   = MakeCellBorderLine( RGB(255,255,255), 0, 10, 0 )
         oCell.RightBorder  = MakeCellBorderLine( RGB(255,255,255), 0, 10, 0 )
         oCell.TopBorder    = MakeCellBorderLine( RGB(255,255,255), 0, 10, 0 )
         oCell.BottomBorder = MakeCellBorderLine( RGB(255,255,255), 0, 10, 0 )
      Next
   Next
End Sub
Function MakeCellBorderLine( nColor, nInnerLineWidth, nOuterLineWidth, nLineDistance ) _
         As com.sun.star.table.BorderLine
   oBorderLine = createUnoStruct( "com.sun.star.table.BorderLine" )
   With oBorderLine
      .Color = nColor
      .InnerLineWidth = nInnerLineWidth
      .OuterLineWidth = nOuterLineWidth
      .LineDistance = nLineDistance
   End With
   MakeCellBorderLine = oBorderLine
End Function

Question: Why we can not modify the border using these code:

oCell.BottomBorder .Color = rgb(128,0,200) and so on.

 

20110414

TextField of OpenOffice swriter can be a password control by Only changing the Model.EchoChar to specific char.