Marc,
The save as doesn't work here. I open a .doc-file and wanted to save it to another .doc-filename.
The commands posted above is not for Save as but for Saving a Document. You may use the below given code to do a Save as
oService := CreateObject( "com.sun.star.ServiceManager" )
oDesktop := oService:CreateInstance( "com.sun.star.frame.Desktop" )
// Opens a specific Document
aProp:={}
oDoc := oDesktop:LoadComponentFromURL( "file:///C:/MyTest/Samples/Resume.odt", "_blank", 0, aProp )
// Insert sample Text
oText:=oDoc:getText() // Create text object
// Create a cursor object (position pointer)
oCursor:= oText:createTextCursor()
oText:insertString(oCursor, ;
"The first line in the created text document."+ CHR(10) + "FWH Rocks!", .F.)
// Alternative method to execute a Save as
oDispatcher:= oService:CreateInstance( "com.sun.star.frame.DispatchHelper" )
aProp:={}
AAdd(aProp,GetPropertyValue(oService, "URL", "file:///C:/MyTest/ansertest.odt") ) // File Name
AAdd(aProp,GetPropertyValue(oService, "FilterName", "writer8") )
oDispatcher:executeDispatch(oDoc:GetCurrentController():GetFrame(), ".uno:SaveAs", "", 0, aProp)
//-----------------------------------------------------//
STATIC FUNCTION GetPropertyValue(oService, cName, xValue )
LOCAL oArg
oArg := oService:Bridge_GetStruct( "com.sun.star.beans.PropertyValue" )
oArg:Name := cName
oArg:Value := xValue
RETURN oArg
Do you know how to do a replace? I want to open a file and replace some strings with another string and than save it.
It will depend on your requirment. If you are you looking for a solution for search and replace, then here it is
aProp:={}
AAdd(aProp,GetPropertyValue(oService, "SearchItem.StyleFamily" , 2 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.CellType" , 0 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.RowDirection" , .T. ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.AllTables" , .F. ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.Backward" , .F. ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.Pattern" , .F. ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.Content" , .F. ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.AsianOptions" , .F. ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.AlgorithmType", 0 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.SearchFlags" , 65536 ) )
// Search String
AAdd(aProp,GetPropertyValue(oService, "SearchItem.SearchString" , "Antony") )
// Replace String
AAdd(aProp,GetPropertyValue(oService, "SearchItem.ReplaceString", "Jerry" ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.Locale" , 255 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.ChangedChars" , 2 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.DeletedChars" , 2 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.InsertedChars", 2 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.TransliterateFlags",1280 ) )
AAdd(aProp,GetPropertyValue(oService, "SearchItem.Command" , 3 ) )
AAdd(aProp,GetPropertyValue(oService, "Quiet" , .T. ) )
oDispatcher:executeDispatch(oDoc:GetCurrentController():GetFrame(), ".uno:ExecuteSearch", "", 0, aProp)
Regards
Anser