| View previous topic :: View next topic |
| Author |
Message |
rajeshsegu Power User

Joined: 20 Dec 2005 Posts: 53
|
Posted: Fri May 12, 2006 2:40 am Post subject: Auto Detect NumberFormats |
|
|
Hello Friends!
I have been trying to auto detect the format of values using the XNumberFormatter. I was search this forum and landed on the below url.
http://www.oooforum.org/forum/viewtopic.phtml?t=5132&highlight=numberformatter
Good that it had a code snippet which makes use of NumberFormatter. But when I tried to exectue the code I get some Proxy$x runtime exception which I could not really understand.
Here is what I am trying to do............
XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
Object urlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext );
XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver);
Object initialObject = xUnoUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, initialObject);
Object context = xPropertySet.getPropertyValue("DefaultContext");
XComponentContext xRemoteContext = (XComponentContext)UnoRuntime.queryInterface(XComponentContext.class, context);
Object formatter = xRemoteContext.getServiceManager().createInstanceWithContext("com.sun.star.util.NumberFormatter", xRemoteContext);
XNumberFormatter xNumberFormatter = (XNumberFormatter) UnoRuntime.queryInterface(XNumberFormatter.class, formatter);
But after I write this code and use xNumberFormatter.detectNumberFormat(0,"1-jan-2005") it throws
$Proxy16.detectNumberFormat(Unknown Source) runtime exception.
Hope there would be an easier way to use XNumberFormatter. Any suggestions would help me a lot............ waiting for those.......
Rajesh Segu |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Fri May 12, 2006 2:04 pm Post subject: |
|
|
Hi,
in OO BASIC it seems to work ...
| Code: | Sub Main
oNumberFormatter = createUnoService("com.sun.star.util.NumberFormatter")
oNumberFormatter.attachNumberFormatsSupplier(ThisComponent)
oFormats = oNumberFormatter.NumberFormatsSupplier.NumberFormats
l = oNumberFormatter.detectNumberFormat(0, "10.3.2006")
msgbox oFormats.getByKey(l).FormatString
l = oNumberFormatter.detectNumberFormat(0, "7 Jan 2003")
msgbox oFormats.getByKey(l).FormatString
l = oNumberFormatter.detectNumberFormat(0, "20,6e-3")
msgbox oFormats.getByKey(l).FormatString
l = oNumberFormatter.detectNumberFormat(0, "Hello")
msgbox oFormats.getByKey(l).FormatString
end sub
|
(Change test strings to english locale, if appropriate) |
|
| Back to top |
|
 |
rajeshsegu Power User

Joined: 20 Dec 2005 Posts: 53
|
Posted: Mon May 29, 2006 1:51 am Post subject: Anyone can help me out? |
|
|
Guys! I badly need to the code to get the xNumberFormatter interface from the UNO service handle for com.sun.star.util.NumberFormatter
The above reply, gives me code for OOBasic but I need to program it using OpenOffice Calc Java API. So please try to give me some insight.
Any help is appreciated. Thank you. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|