I am new to OOo API. I am currently using a .doc file as a template and
doing a search and replace for the string values I wish to update but the
doc contains check boxes that I wish to set as checked but cannot find
anything on how to do this can someone help me.
The following is what I am using for the search and replace:-
public String doUpdate(String[] replace, String[] replaceWith,
String refNum, String file){
String oooExeFolder = _conf.getProperty("app.ooo_exe");
String templateDir = _conf.getProperty("wa.template_dir");
String waDir = _conf.getProperty("wa.webapp_dir");
// get the remote office component context
List<String> oooOptions = OOoServer.getDefaultOOoOptions();
oooOptions.add("-nofirststartwizard");
OOoServer oooServer = new OOoServer(oooExeFolder, oooOptions);
BootstrapSocketConnector bsc = new
BootstrapSocketConnector(oooServer);
try{
XComponentContext xContext = bsc.connect();
Logfile.log("UPDATE TEMPLATE", "Connected to a running office
...");
// Get the remote office service manager
XMultiComponentFactory xMCF = xContext.getServiceManager();
// Get the root frame (i.e. desktop) of openoffice framework.
Object oDesktop =
xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
Object oDataForm =
xMCF.createInstanceWithContext("com.sun.star.form.component.DataForm",
xContext);
// Desktop has 3 interfaces. The XComponentLoader interface
provides
ability to load
// components.
XComponentLoader xCompLoader = (XComponentLoader)
UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
// URL of the component to be loaded
if(!templateDir.startsWith("/"))
templateDir = "/"+templateDir;
if(!waDir.startsWith("/"))
waDir = "/"+waDir;
String sUrl = "file://"+templateDir+"/"+file;
System.out.println("Before loading "+sUrl);
// Load the document, which will be displayed. More param info
in
apidoc
XComponent xComp = xCompLoader.loadComponentFromURL(sUrl,
"_blank", 0,
new PropertyValue[0]);
// Get the textdocument
XTextDocument aTextDocument =
(XTextDocument)UnoRuntime.queryInterface(
XTextDocument.class, xComp);
XReplaceDescriptor xReplaceDescr = null;
//XSearchDescriptor xSearchDescriptor = null;
XReplaceable xReplaceable = null;
xReplaceable = (XReplaceable)
UnoRuntime.queryInterface(
XReplaceable.class, aTextDocument);
// You need a descriptor to set properies for Replace
xReplaceDescr = (XReplaceDescriptor)
xReplaceable.createReplaceDescriptor();
for( int iArrayCounter = 0; iArrayCounter < replace.length;
iArrayCounter++ )
{
System.out.println(replace[iArrayCounter] +
" -> " + replaceWith[iArrayCounter]);
// Set the properties the replace method need
xReplaceDescr.setSearchString(replace[iArrayCounter] );
xReplaceDescr.setReplaceString(replaceWith[iArrayCounter] );
// Replace all words
xReplaceable.replaceAll( xReplaceDescr );
}
if(!FileUtilities.checkDirectoryExists(waDir+"/"+refNum)){
FileUtilities.createDirectory(waDir+"/"+refNum);
}
String storeUrl = "file://"+waDir+"/"+refNum+"/"+file;
XStorable xStorable =
(XStorable)UnoRuntime.queryInterface(XStorable.class, aTextDocument);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "MS Word 97";
xStorable.storeAsURL(storeUrl, storeProps);
//Dispose of text document
aTextDocument.dispose();
}
catch( Exception e) {
System.out.println(e.getMessage());
}
--
View this message in context:
http://www.nabble.com/Handling-Check-Boxes-in-.doc-tp24901176p24901176.html
Sent from the openoffice - api dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]