[Solved] VB : Different style in a cell

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
OPENMSA
Posts: 3
Joined: Wed Sep 10, 2014 5:29 pm

[Solved] VB : Different style in a cell

Post by OPENMSA »

Hello,

I am trying to set a cell with 3 different styles (fonts, size) in macro VB.

Is it possible?
How?
Last edited by OPENMSA on Fri Sep 12, 2014 10:03 am, edited 1 time in total.
Open Office 3.1.0
on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31349
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: VB : Different style in a cell

Post by Villeroy »

You just do not know what a style is.
https://wiki.openoffice.org/wiki/Docume ... _Templates

Code: Select all

objCell.CellStyle = "My_Sophisticated_Cell_Style_With_Dozends_of_Attributes"
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
OPENMSA
Posts: 3
Joined: Wed Sep 10, 2014 5:29 pm

Re: VB : Different style in a cell

Post by OPENMSA »

It seems style apply on the whole cell. Let's forget about style :
I am trying to set a cell with 3 differents fonts & size in macro VB.

Is it possible?
How?
Open Office 3.1.0
on Windows 7
User avatar
karolus
Volunteer
Posts: 1234
Joined: Sat Jul 02, 2011 9:47 am

Re: VB : Different style in a cell

Post by karolus »

Hallo
OPENMSA wrote:...in macro VB.

Is it possible?
How?
Yes, of course -- but what the hell is VB :twisted:

Code: Select all

def word_formatter():
    doc = XSCRIPTCONTEXT.getDocument()
    sel = doc.CurrentSelection #works for one single selected Cell !!
    cursor = sel.createTextCursor()
    sentence = 'just three words'.split()
    sizes = (12,20,15)
    fonts = ('Carlito', 'Linux Biolinum Keyboard', 'Droid Sans')
    for word, size, font in zip(sentence, sizes, fonts):
        cursor = cursor.End
        cursor.CharHeight = size
        cursor.CharFontName = font
        cursor.Text.insertString(cursor, '%s ' % word, False)
Karolus
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (Bookworm) (on RaspberryPI5)
OPENMSA
Posts: 3
Joined: Wed Sep 10, 2014 5:29 pm

Re: VB : Different style in a cell

Post by OPENMSA »

Thanks you so much, it works!

Tip : change charWeight, charPosture after a insertControlCharacter (LINE_BREAK...)
Open Office 3.1.0
on Windows 7
User avatar
karolus
Volunteer
Posts: 1234
Joined: Sat Jul 02, 2011 9:47 am

Re: VB : Different style in a cell

Post by karolus »

OPENMSA wrote:Thanks you so much, it works!

Tip : change charWeight, charPosture after a insertControlCharacter (LINE_BREAK...)
change

Code: Select all

'%s '
to

Code: Select all

'%s\n'
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (Bookworm) (on RaspberryPI5)
Post Reply