OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to insert a Euro sign using Python ??

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
steve.pole
General User
General User


Joined: 10 Nov 2005
Posts: 6

PostPosted: Tue Mar 21, 2006 3:05 pm    Post subject: How to insert a Euro sign using Python ?? Reply with quote

Hi all,

in my Python script, I would like to insert a text into a writer doc that contains a Euro sign (). Inserting all kinds of Unicode chars ("special characters") under Python is actually a piece of cake:

Code:
string = u"some text \u0177 more text \u1092 more more text"
text.insertString (textCursor, string, False)

The problem is that in the special chars table, the Euro sign does not appear, the only way to insert it manually is AltGr-E. For the moment, I use 'EUR', but that can't be the best solution. Working with Windows XP / OOo 2.0.2

Does someone know how this can be achieved ?

TIA,

CU Z>
Back to top
View user's profile Send private message
james_h
Super User
Super User


Joined: 05 Nov 2005
Posts: 883

PostPosted: Tue Mar 21, 2006 6:51 pm    Post subject: OOo 2 Writer: The Unicode value of Euro is 8364 Reply with quote

OpenOffice.org 2 Writer: The Unicode value of Euro is 8364
According to my Insert > Special Characters menu, the symbol for the Euro has the Unicode Hexadecimal number of 20AC. Therefore, the value for Euro in decimals is 8364.

In Basic, your function would look something like:

Code:
sub Main2
dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "some text " & chr$(&H20AC) & " more text " & chr$(8364) & " more more text"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub


So in python you could try:

Code:
string = u"some text \u8364 more text \u8364 more more text"
text.insertString (textCursor, string, False)


Of course, the font you are using would have to include the Euro for this to work.
Back to top
View user's profile Send private message
steve.pole
General User
General User


Joined: 10 Nov 2005
Posts: 6

PostPosted: Wed Mar 22, 2006 3:14 am    Post subject: How to insert a Euro sign using Python ?? [SOLVED] Reply with quote

Hey James,

thank you very much for your reply. Looks like I just haven't scrolled down far enough (DOH!). I promise, I'll have a deeper look next time. It was really late yesterday, though.
Your Python code examples is also almost perfect. For anyone looking for a solution to the same problem: The unicode numbers are hexadecimal, that didn't really show in my first example.
Inserting a Euro sign with Python thus is done like this:
Code:
string = u"some text \u20AC more text \u20AC more more text"
text.insertString (textCursor, string, False)

(Is this snippet too trivial to post in the snippets section ?)
As James mentioned, the font in use must include the Euro for this to work, but most commons ones do (I use Tahoma).

Regards,

CU Z>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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