home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="UTF-8"?>
-
- <script:module xmlns:script="http://openoffice.org/2000/script" script:name="GetTexts" script:language="StarBasic">Option Explicit
- ' Option f├╝r doppelte Strings
- ' Alternativtexte, Namen usw f├╝r HTML-Seiten--> ist Anbindung an StarOfficeAPI geplant?
- ' Verlustanzeige "Wo ist Peggy?"
- ' Überschriften für Textfelder
- ' GetTextFrames mit Peter absprechen
- ' Ole - Objekte auch mit einbeziehen?
- ' Redimensionierung des LogArrays, wenn Implementierung so weit ist
- ' Namen von Notizenseiten mit Peter durchsprechen
-
- ' Macro-Description:
- ' This Macro extracts the Strings out of the currently activated document und inserts them into a logdocument
- ' The aim of the macro is to provide the programmer an insight into the StarOffice API
- ' It focusses on how document-Objects are accessed.
- ' Therefor not only texts of the document-body are retrieved but also Texts of general
- ' document Objects like, Annotations, charts and general Document Information
-
- Public oLogDocument, oLogText, oLogCursor, oLogHeaderStyle, oLogBodyTextStyle as Object
- Public oDocument as Object
- Public LogArray(1000) as String
- Public LogIndex as Integer
- Public oLocHeaderStyle as Object
-
- Sub Main
- Dim sDocType as String
- Dim oHyperCursor as Object
- Dim oCharStyles as Object
-
- BasicLibraries.LoadLibrary("Tools")
-
- On Local Error GoTo NODOCUMENT
- oDocument = StarDesktop.ActiveFrame.Controller.Model
- sDocType = GetDocumentType(oDocument)
- NODOCUMENT:
- If Err <> 0 Then
- Msgbox("This Macro extracts all Data of the displayed Writer-, Calc or Draw-Documents." & chr(13) &_
- "To start this macro you have to activate a Document first!" , 16, "StarOffice 5.2")
- Exit Sub
- End If
- On Local Error Goto 0
-
- ' Open a new document where all the texts are inserted
- oLogDocument = StarDesktop.LoadComponentFromURL( "staroffice:factory/swriter","_blank",0,NoArgs())
- oLogText = oLogDocument.Text
-
- ' create and define the character styles of the Log-document
- oCharStyles = oLogDocument.StyleFamilies.GetByName("CharacterStyles")
- oLogHeaderStyle = oLogDocument.createInstance("com.sun.star.style.CharacterStyle")
- oLogHeaderStyle.charWeight = com.sun.star.awt.FontWeight.BOLD
- oLogBodyTextStyle = oLogDocument.createInstance("com.sun.star.style.CharacterStyle")
- oCharStyles.InsertbyName("LogHeading", oLogHeaderStyle)
- oCharStyles.InsertbyName("LogBodyText", oLogBodyTextStyle)
-
- ' Insert the title of the activated document as a hyperlink
- oHyperCursor = oLogText.createTextCursor()
- oHyperCursor.charWeight = com.sun.star.awt.FontWeight.BOLD
- oHyperCursor.gotoStart(False)
- oHyperCursor.HyperLinkURL = oDocument.URL
- oHyperCursor.HyperLinkTarget = oDocument.URL
- If oDocument.DocumentInfo.Title <> "" Then
- oHyperCursor.HyperlinkName = oDocument.DocumentInfo.Title
- End If
- oLogText.insertString(oHyperCursor, oDocument.DocumentInfo.Title, False)
- oLogText.insertControlCharacter(oHyperCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
-
- oLogCursor = oLogText.createTextCursor()
- oLogCursor.GotoEnd(False)
- ' "Switch off" the Hyperlink - Properties
- oLogCursor.SetPropertyToDefault("HyperLinkURL")
- oLogCursor.SetPropertyToDefault("HyperLinkTarget")
- oLogCursor.SetPropertyToDefault("HyperLinkName")
- LogIndex = 0
-
- ' Get the Properties of the document Info
- GetDocumentInfo()
-
- Select Case sDocType
- Case "sWriter"
- GetWriterStrings()
- Case "sCalc"
- GetCalcStrings()
- Case "sDraw"
- GetDrawStrings()
- Case Else
- Msgbox("This Macro only works with Writer-, Calc or Draw/Impress-Documents!", 16, "StarOffice 5.2")
- End Select
-
- End Sub
-
-
- ' ***********************************************Calc-Documents**************************************************
-
- Sub GetCalcStrings()
- Dim i, n as integer
- Dim oSheet as Object
- Dim SheetName as String
- Dim oSheets as Object
- ' Create a sequence of all sheets within the document
- oSheets = oDocument.Sheets
-
- For i = 0 to osheets.Count - 1
- oSheet = osheets.GetbyIndex(i)
- SheetName = oSheet.Name
- MakeLogHeadLine("Sheet No " & i & "(" & SheetName & ")" )
-
- ' Check the "body" of the sheet
- GetCellTexts(oSheet)
-
- If oSheet.IsScenario then
- MakeLogHeadLine("Scenario-Comments of " & SheetName & "'")
- WriteStringtoLogFile(osheet.ScenarioComment)
- End if
-
- GetAnnotations(oSheet, "Annotations of '" & SheetName & "'")
-
- GetChartStrings(oSheet, "Charts of '" & SheetName & "'")
-
- GetControlStrings(oSheet.DrawPage, "Controls of '" & SheetName & "'")
- Next
-
- ' Pictures
- GetCalcGraphicNames()
-
- GetNamedRanges()
- End Sub
-
-
- Sub GetCellTexts(oSheet as Object)
- Dim BigRange, BigEnum, oCell as Object
- BigRange = oDocument.CreateInstance("com.sun.star.sheet.SheetCellRanges")
- BigRange.InsertbyName("",oSheet)
- BigEnum = BigRange.GetCells.CreateEnumeration
- While BigEnum.hasmoreElements
- oCell = BigEnum.NextElement
- If (oCell.Type = com.sun.star.util.NumberFormat.TEXT) AND (oCell.String <> "") then
- WriteStringtoLogFile(oCell.String)
- End If
- Wend
- End Sub
-
-
- Sub GetAnnotations(oSheet as Object, HeaderLine as String)
- Dim oNotes as Object
- Dim n as Integer
- oNotes = oSheet.getAnnotations
- If oNotes.hasElements() then
- MakeLogHeadLine(HeaderLine)
- For n = 0 to oNotes.Count-1
- WriteStringtoLogFile(oNotes.GetbyIndex(n).String)
- Next
- End if
- End Sub
-
-
- Sub GetNamedRanges()
- Dim i as integer
- MakeLogHeadLine("Named Ranges")
- For i = 0 To oDocument.NamedRanges.Count - 1
- WriteStringtoLogFile(oDocument.NamedRanges.GetbyIndex(i).Name)
- Next
- End Sub
-
-
- Sub GetCalcGraphicNames()
- Dim n,m as integer
- MakeLogHeadLine("Pictures")
- For n = 0 To oDocument.Drawpages.count-1
- For m = 0 To oDocument.Drawpages.GetbyIndex(n).Count - 1
- WriteStringtoLogFile(oDocument.DrawPages.GetbyIndex(n).GetbyIndex(m).Text.String)
- Next m
- Next n
- End Sub
-
-
- ' ***********************************************Writer-Documents**************************************************
-
- Sub GetParagraphTexts(oParaObject as Object, HeadLine as String)
- Dim ParaEnum as Object
- Dim oPara as Object
- Dim oTextPortEnum as Object
- Dim oTextPortion as Object
- Dim i as integer
- Dim oCellNames()
- Dim oCell as Object
-
- MakeLogHeadLine(HeadLine)
- ParaEnum = oParaObject.Text.CreateEnumeration
-
- While ParaEnum.HasMoreElements
- oPara = ParaEnum.NextElement
-
- ' Note: The Enumeration ParaEnum lists all tables and Paragraphs.
- ' Therefor we have to find out what kind of object "oPara" actually is
- If oPara.supportsService("com.sun.star.text.Paragraph") Then
- ' "oPara" is a Paragraph
- oTextPortEnum = oPara.createEnumeration
- While oTextPortEnum.hasmoreElements
- oTextPortion = oTextPortEnum.nextElement()
- WriteStringToLogFile(oTextPortion.String)
- Wend
- Else
- ' "oPara" is a table
- oCellNames = oPara.CellNames
- For i = 0 To Ubound(oCellNames())
- If oCellNames(i) <> "" Then
- oCell = oPara.getCellByName(oCellNames(i))
- WriteStringToLogFile(oCell.String)
- End If
- Next
- End If
- Wend
- End Sub
-
-
-
- Sub GetChartStrings(oSheet as Object, HeaderLine as String)
- Dim i as Integer
- Dim aChartObject as Object
- Dim aChartDiagram as Object
-
- MakeLogHeadLine(HeaderLine)
-
- For i = 0 to oSheet.Charts.Count-1
- aChartObject = oSheet.Charts.GetByIndex(i).EmbeddedObject
- If aChartObject.HasSubTitle then
- WriteStringToLogFile(aChartObject.SubTitle.String)
- End If
-
- If aChartObject.HasMainTitle then
- WriteStringToLogFile(aChartObject.Title.String)
- End If
-
- aChartDiagram = aChartObject.Diagram
-
- If aChartDiagram.hasXAxisTitle Then
- WriteStringToLogFile(aChartDiagram.XAxisTitle)
- End If
-
- If aChartDiagram.hasYAxisTitle Then
- WriteStringToLogFile(aChartDiagram.YAxisTitle)
- End If
-
- If aChartDiagram.hasZAxisTitle Then
- WriteStringToLogFile(aChartDiagram.ZAxisTitle)
- End If
- Next i
- End Sub
-
-
-
- Sub GetFrameTexts()
- Dim i as integer
- Dim oTextFrame as object
- Dim oFrameEnum as Object
- Dim oFramePort as Object
- Dim oFrameTextEnum as Object
- Dim oFrameTextPort as Object
-
- MakeLogHeadLine("Text Frames")
- For i = 0 to oDocument.TextFrames.Count-1
- oTextFrame = oDocument.TextFrames.GetbyIndex(i)
- WriteStringToLogFile(oTextFrame.Name)
-
- ' Is the frame bound to the Page
- If oTextFrame.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE Then
- GetParagraphTexts(oTextFrame, "Textframe Content")
- End If
-
- oFrameEnum = oTextFrame.CreateEnumeration
- While oFrameEnum.HasMoreElements
- oFramePort = oFrameEnum.NextElement
- If oFramePort.supportsService("com.sun.star.text.Paragraph") then
- oFrameTextEnum = oFramePort.createEnumeration
- While oFrameTextEnum.HasMoreElements
- oFrameTextPort = oFrameTextEnum.NextElement
- If oFrameTextPort.SupportsService("com.sun.star.text.TextFrame") Then
- WriteStringtoLogFile(oFrameTextPort.String)
- End If
- Wend
- Else
- WriteStringtoLogFile(oFramePort.Name)
- End if
- Wend
- Next
- End Sub
-
-
- Sub GetTextFieldStrings()
- Dim aTextField as Object
- Dim i as integer
- Dim CurElement as Object
- MakeLogHeadLine("TextFields")
- aTextfield = oDocument.getTextfields.CreateEnumeration
- While aTextField.hasmoreElements
- CurElement = aTextField.NextElement
- If CurElement.PropertySetInfo.hasPropertybyName("Content") Then
- WriteStringtoLogFile(CurElement.Content)
- ElseIf CurElement.PropertySetInfo.hasPropertybyName("PlaceHolder") Then
- WriteStringtoLogFile(CurElement.PlaceHolder)
- WriteStringtoLogFile(CurElement.Hint)
- ElseIf Curelement.TextFieldMaster.PropertySetInfo.HasPropertybyName("Content") then
- WriteStringtoLogFile(CurElement.TextFieldMaster.Content)
- End If
- Wend
- End Sub
-
-
-
- Sub GetLinkedFileNames()
- Dim oDocSections as Object
- Dim LinkedFileName as String
- Dim i as Integer
- If Right(oDocument.URL,3) = "sgl" Then
- MakeLogHeadLine("Sub Documents")
- oDocSections = oDocument.TextSections
- For i = 0 to oDocSections.Count - 1
- LinkedFileName = oDocSections.GetbyIndex(i).FileLink.FileURL
- If LinkedFileName <> "" Then
- WriteStringToLogFile(LinkedFileName)
- End If
- Next i
- End If
- End Sub
-
-
- Sub GetSectionNames()
- Dim i as integer
- Dim oDocSections as Object
- MakeLogHeadLine("Sections")
- oDocSections = oDocument.TextSections
- For i = 0 to oDocSections.Count-1
- WriteStringtoLogFile(oDocSections.GetbyIndex(i).Name)
- Next
- End Sub
-
-
- Sub GetWriterStrings()
- GetParagraphTexts(oDocument, "Document Body")
- GetGraphicNames()
- GetStyles()
- GetControlStrings(oDocument.DrawPage, "Controls")
- GetTextFieldStrings()
- GetSectionNames()
- GetFrameTexts()
- GetHyperLinks
- GetLinkedFileNames()
- End Sub
-
-
- ' ***********************************************Draw-Documents**************************************************
-
- Sub GetDrawPageTitles(LocObject as Object)
- Dim n as integer
- Dim oPage as Object
-
- For n = 0 to LocObject.Count - 1
- oPage = LocObject.GetbyIndex(n)
- WriteStringtoLogFile(oPage.Name)
- ' Is the Page a DrawPage and not a MasterPage?
- If oPage.supportsService("com.sun.star.drawing.DrawPage")then
- ' Get the Name of the NotesPage (only relevant for Impress-Documents)
- If oDocument.supportsService("com.sun.star.presentation.PresentationDocument") then
- WriteStringtoLogFile(oPage.NotesPage.Name)
- End If
- End If
- Next
- End Sub
-
-
- Sub GetPageStrings(oPages as Object)
- Dim m, n, s as Integer
- Dim oPage, oPageElement, oShape as Object
- For n = 0 to oPages.Count-1
- oPage = oPages.GetbyIndex(n)
- If oPage.HasElements then
- For m = 0 to oPage.Count-1
- oPageElement = oPage.GetByIndex(m)
- If HasUnoInterfaces(oPageElement,"com.sun.star.container.XIndexAccess") Then
- ' The Object "oPageElement" a group of Shapes, that can be accessed by their index
- For s = 0 To oPageElement.Count - 1
- WriteStringToLogFile(oPageElement.GetByIndex(s).String)
- Next s
- Else
- WriteStringtoLogFile(oPageElement.String)
- End If
- Next
- End If
- Next
- End Sub
-
-
- Sub GetDrawStrings()
- Dim oDPages, oMPages as Object
-
- oDPages = oDocument.DrawPages
- oMPages = oDocument.Masterpages
-
- MakeLogHeadLine("Titles")
- GetDrawPageTitles(oDPages)
- GetDrawPageTitles(oMPages)
-
- MakeLogHeadLine("Document Body")
- GetPageStrings(oDPages)
- GetPageStrings(oMPages)
- End Sub
-
-
- ' ***********************************************Misc**************************************************
-
- Sub GetDocumentInfo()
- Dim oDocuInfo as Object
- MakeLogHeadLine("Document Info")
- oDocuInfo = oDocument.DocumentInfo
- WriteStringToLogFile(oDocuInfo.Title)
- WriteStringToLogFile(oDocuInfo.Description)
- WriteStringToLogFile(oDocuInfo.Theme)
- WriteStringToLogFile(oDocuInfo.Author)
- WriteStringToLogFile(oDocuInfo.ReplyTo)
- WriteStringToLogFile(oDocuInfo.Recipient)
- WriteStringToLogFile(oDocuInfo.References)
- WriteStringToLogFile(oDocuInfo.Keywords)
- End Sub
-
-
- Sub GetHyperlinks()
- Dim i as integer
- Dim oCrsr as Object
- Dim oAllHyperLinks as Object
- Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
- Dim oSearchDesc as Object
-
- MakeLogHeadLine("HyperLinks")
- ' create a Search-Descriptor
- oSearchDesc = oDocument.CreateSearchDescriptor
- oSearchDesc.Valuesearch = False
-
- ' define the Search-attributes
- srchattributes(0).Name = "HyperLinkURL"
- srchattributes(0).Value = ""
- oSearchDesc.SetSearchAttributes(SrchAttributes())
-
- oAllHyperLinks = oDocument.findAll(oSearchDesc())
-
- For i = 0 to oAllHyperLinks.Count - 1
- oFound = oAllHyperLinks(i)
- oCrsr = oFound.Text.createTextCursorByRange(oFound)
- WriteStringToLogFile(oCrs.HyperLinkURL) 'Url
- WriteStringToLogFile(oCrs.HyperLinkTarget) 'Name
- WriteStringToLogFile(oCrs.HyperLinkName) 'Frame
- Next i
- End Sub
-
-
- Sub GetGraphicNames()
- Dim i as integer
- Dim oDocGraphics as Object
- MakeLogHeadLine("Pictures")
- oDocGraphics = oDocument.GraphicObjects
- For i = 0 to oDocGraphics.count - 1
- WriteStringtoLogFile(oDocGraphics.GetbyIndex(i).Name)
- Next
- End Sub
-
-
- Sub GetStyles()
- Dim m,n as integer
- MakeLogHeadLine("Userdefined Templates")
-
- ' Check all StyleFamilies(i.e. PageStyles, ParagraphStyles, CharacterStyles, cellStyles)
- For n = 0 to oDocument.StyleFamilies.Count - 1
- For m = 0 to oDocument.StyleFamilies.getbyIndex(n).Count-1
- If oDocument.StyleFamilies.GetbyIndex(n).getbyIndex(m).IsUserDefined then
- WriteStringtoLogFile(oDocument.StyleFamilies.GetbyIndex(n).getbyIndex(m).Name)
- End If
- Next
- Next
- End Sub
-
-
- Sub GetControlStrings(oDPage as Object, HeaderLine as String)
- Dim aForm as Object
- Dim m,n as integer
- MakeLogHeadLine(HeaderLine)
- 'SearchFor all possible Controls
- For n = 0 to oDPage.Forms.Count - 1
- aForm = oDPage.Forms(n)
- For m = 0 to aForm.Count-1
- GetControlContent(aForm.GetbyIndex(m))
- Next
- Next
- End Sub
-
-
- Sub GetControlContent(LocControl as Object)
- Dim i as integer
-
- If LocControl.PropertySetInfo.HasPropertybyName("Label") then
- WriteStringtoLogFile(LocControl.Label)
-
- ElseIf LocControl.SupportsService("com.sun.star.form.component.ListBox") then
- For i = 0 to Ubound(LocControl.StringItemList())
- WriteStringtoLogFile(LocControl.StringItemList(i))
- Next
- End If
- If LocControl.PropertySetInfo.HasPropertybyName("HelpText") then
- WriteStringtoLogFile(LocControl.Helptext)
- End If
- End Sub
-
- ' ***********************************************LogDocument**************************************************
-
- Sub WriteStringtoLogFile( sString as String)
-
- ' Schreibt den String in ein Array
- If (Not FieldInArray(LogArray(),LogIndex,sString))AND (NOT ISNULL(sString)) Then
- LogArray(LogIndex) = sString
- LogIndex = LogIndex + 1
- oLogText.insertString(oLogCursor,sString,False)
- oLogText.insertControlCharacter(oLogCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
- End If
- End Sub
-
-
- Sub MakeLogHeadLine(HeadText as String)
- oLogCursor.CharStyle = "LogHeading"
- oLogText.insertControlCharacter(oLogCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
- oLogText.insertString(oLogCursor,HeadText,False)
- oLogText.insertControlCharacter(oLogCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
- oLogCursor.CharStyle = "LogBodyText"
- End Sub
-
-
-
- 'Sub GetHTMLStrings(SearchString as String)
- 'Dim i,AsciiCount as integer
- 'Dim AsciiLocChar as string
- 'Dim TTString,AddString as String
- 'Dim oTextCursor as object
- 'Dim LeaveLoop as Boolean
-
- ' oSearchDesc = oDocument.createSearchDescriptor()
- ' oSearchDesc.SearchRegularExpression = True
- ' oSearchDesc.Searchstring = SearchString & """" & "*" & """"
- ' oFoundall = oDocument.FindAll(oSearchDesc)
-
- ' For i = 0 to oFoundAll.Count-1
- ' oFound = oFoundall(i)
- ' oTextCursor = oDocument.text.CreateTextCursorbyRange(oFound)
- ' oTextCursor.GotoNextWord(false)
- ' oTextCursor.GotoStartofWord(True)
- ' oTextCursor.GoRight(1,True)
- ' TTString = oTextCursor.String
- ' If Left(TTString,1) = """" Then
- ' LeaveLoop = False
- ' oTextCursor.GoRight(1,True)
- ' Do
- ' oTextCursor.GoRight(1,True)
- ' TTString = TTString + Right(oTextCursor.String,1)
- ' If Right(oTextCursor.String,1) = """" Then
- ' TTString = ReplaceString(TTString,"","""")
- ' LeaveLoop = True
- ' End If
- ' Loop Until LeaveLoop = True
- '
- ' End If
- '
- ' If TTString <> "" then
- ' TTString = ReplaceHTMLChars(TTString)
- ' WriteStringtoLogFile(TTString)
- ' End if
- ' Next i
- '
- 'End Sub
-
- ' If sDocMimeType = "text/html" then
- ' FileProperties(0).Name = "FilterName"
- ' FileProperties(0).Value = "swriter: TEXT"
- ' FilePath = oDocument.URL
- ' oDocument.Dispose
- '
- ' oDocument = OpenDocument(FilePath,FileProperties(),StarDesktop) '!!!!!!!
- '
- ' MakeLogHeadLine("Alternativtexte")
- ' GetHTMLStrings("ALT=")
- '
- ' MakeLogHeadLine("Referenzen")
- ' GetHTMLStrings("HREF=")
- '
- ' MakeLogHeadLine("Namen")
- ' GetHTMLStrings("NAME=")
- ' Else
-
-
- Sub LoadLibrary(sLibname as String)
- Dim oArg(0) as new com.sun.star.beans.PropertyValue
- Dim oUrl as new com.sun.star.util.URL
- Dim oTrans as Object
- Dim oDisp as Object
-
- oArg(0).Name = "LibraryName"
- oArg(0).Value = sLibname
-
- oTrans = createUNOService("com.sun.star.util.URLTransformer")
- oUrl.Complete = "slot:6517"
- oTrans.parsestrict(oUrl)
-
- oDisp = StarDesktop.currentFrame.queryDispatch(oUrl, "_self", 0)
- oDisp.dispatch(oUrl, oArg())
- End Sub
- </script:module>
-