REM  *****  BASIC  *****




sub Main ( cFile )
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
rem document   = ThisComponent.CurrentController.Frame
cURL = ConvertToURL( cFile )
   ' Open the document. Just blindly assume that the document 
   ' is of a type that OOo will correctly recognize and open 
   ' without specifying an import filter.
   document = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
            Array(MakePropertyValue( "Hidden", True ),))
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem tb^Properties.Title擾----------------------------------------------------------------------
GlobalScope.BasicLibraries.LoadLibrary("Tools")
oUrl = FileNameOutOfPath(cFile)
oUrl = Left( oUrl , Len( oUrl ) - 4 ) 

rem J[\ԏ----------------------------------------------------------------------
dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:GoToStartOfDoc", "", 0, Array())

rem SampleAȀ----------------------------------------------------------------------
dim args2(18) as new com.sun.star.beans.PropertyValue
args2(0).Name = "SearchItem.StyleFamily"
args2(0).Value = 2
args2(1).Name = "SearchItem.CellType"
args2(1).Value = 0
args2(2).Name = "SearchItem.RowDirection"
args2(2).Value = true
args2(3).Name = "SearchItem.AllTables"
args2(3).Value = false
args2(4).Name = "SearchItem.Backward"
args2(4).Value = false
args2(5).Name = "SearchItem.Pattern"
args2(5).Value = false
args2(6).Name = "SearchItem.Content"
args2(6).Value = false
args2(7).Name = "SearchItem.AsianOptions"
args2(7).Value = false
args2(8).Name = "SearchItem.AlgorithmType"
args2(8).Value = 0
args2(9).Name = "SearchItem.SearchFlags"
args2(9).Value = 65536
args2(10).Name = "SearchItem.SearchString"
args2(10).Value = "SampleAA"
args2(11).Name = "SearchItem.ReplaceString"
args2(11).Value = "SampleBB"
args2(12).Name = "SearchItem.Locale"
args2(12).Value = 255
args2(13).Name = "SearchItem.ChangedChars"
args2(13).Value = 2
args2(14).Name = "SearchItem.DeletedChars"
args2(14).Value = 2
args2(15).Name = "SearchItem.InsertedChars"
args2(15).Value = 2
args2(16).Name = "SearchItem.TransliterateFlags"
args2(16).Value = 1280
args2(17).Name = "SearchItem.Command"
args2(17).Value = 3
args2(18).Name = "Quiet"
args2(18).Value = true

dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:ExecuteSearch", "", 0, args2())

rem J[\ԏɖ߂----------------------------------------------------------------------
dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:GoToStartOfDoc", "", 0, Array())

rem SampleCC̏----------------------------------------------------------------------
dim args14(18) as new com.sun.star.beans.PropertyValue
args14(0).Name = "SearchItem.StyleFamily"
args14(0).Value = 2
args14(1).Name = "SearchItem.CellType"
args14(1).Value = 0
args14(2).Name = "SearchItem.RowDirection"
args14(2).Value = true
args14(3).Name = "SearchItem.AllTables"
args14(3).Value = false
args14(4).Name = "SearchItem.Backward"
args14(4).Value = false
args14(5).Name = "SearchItem.Pattern"
args14(5).Value = false
args14(6).Name = "SearchItem.Content"
args14(6).Value = false
args14(7).Name = "SearchItem.AsianOptions"
args14(7).Value = false
args14(8).Name = "SearchItem.AlgorithmType"
args14(8).Value = 0
args14(9).Name = "SearchItem.SearchFlags"
args14(9).Value = 65536
args14(10).Name = "SearchItem.SearchString"
args14(10).Value = "SampleCC"
args14(11).Name = "SearchItem.ReplaceString"
args14(11).Value = "SampleDD"
args14(12).Name = "SearchItem.Locale"
args14(12).Value = 255
args14(13).Name = "SearchItem.ChangedChars"
args14(13).Value = 2
args14(14).Name = "SearchItem.DeletedChars"
args14(14).Value = 2
args14(15).Name = "SearchItem.InsertedChars"
args14(15).Value = 2
args14(16).Name = "SearchItem.TransliterateFlags"
args14(16).Value = 1280
args14(17).Name = "SearchItem.Command"
args14(17).Value = 3
args14(18).Name = "Quiet"
args14(18).Value = true

dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:ExecuteSearch", "", 0, args14())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:GoToStartOfDoc", "", 0, Array())

rem tb^̕ύX----------------------------------------------------------------------
dim args16(17) as new com.sun.star.beans.PropertyValue
args16(0).Name = "Properties.UseUserData"
args16(0).Value = true
args16(1).Name = "Properties.DeleteUserData"
args16(1).Value = false
args16(2).Name = "Properties.Title"
args16(2).Value = oUrl
args16(3).Name = "Properties.Subject"
args16(3).Value = ""
args16(4).Name = "Properties.KeyWords"
args16(4).Value = ""
args16(5).Name = "Properties.Description"
args16(5).Value = ""
args16(6).Name = "Properties.AutoReload"
args16(6).Value = false
args16(7).Name = "Properties.AutoReloadTime"
args16(7).Value = 0
args16(8).Name = "Properties.AutoReloadURL"
args16(8).Value = ""
args16(9).Name = "Properties.AutoReloadFrame"
args16(9).Value = ""
args16(10).Name = "Properties.Field1Title"
args16(10).Value = "Info 3"
args16(11).Name = "Properties.Field2Title"
args16(11).Value = "Info 4"
args16(12).Name = "Properties.Field3Title"
args16(12).Value = "test1"
args16(13).Name = "Properties.Field4Title"
args16(13).Value = "test2"
args16(14).Name = "Properties.Field1"
args16(14).Value = ""
args16(15).Name = "Properties.Field2"
args16(15).Value = ""
args16(16).Name = "Properties.Field3"
args16(16).Value = "test3"
args16(17).Name = "Properties.Field4"
args16(17).Value = "test4"

dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:SetDocumentProperties", "", 0, args16())

rem ڎE̍XV----------------------------------------------------------------------
rem dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:UpdateCurIndex", "", 0, Array())

rem ۑ----------------------------------------------------------------------
dispatcher.executeDispatch(document.getCurrentController().getFrame(), ".uno:Save", "", 0, Array())

rem PDFo-----------------------------------------------
SaveAsPDF( cFile )

document.close(True)

end sub

' Save document as an Acrobat PDF file.
Sub SaveAsPDF( cFile )
   cURL = ConvertToURL( cFile )
   ' Open the document. Just blindly assume that the document 
   ' is of a type that OOo will correctly recognize and open 
   ' without specifying an import filter.
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
            Array(MakePropertyValue( "Hidden", True ),))

   cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
   cURL = ConvertToURL( cFile )
   
   ' Save the document using a filter.   
   oDoc.storeToURL( cURL, Array(_
            MakePropertyValue( "FilterName", "writer_pdf_Export" ),)
   
   oDoc.close( True )
End Sub

Function MakePropertyValue( Optional cName As String, Optional uValue ) _
   As com.sun.star.beans.PropertyValue
   Dim oPropertyValue As New com.sun.star.beans.PropertyValue
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function
