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

[SOLVED] How to set different font in multi-lines cell?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
sevalav
OOo Enthusiast
OOo Enthusiast


Joined: 19 Sep 2009
Posts: 119

PostPosted: Tue Oct 19, 2010 2:13 pm    Post subject: [SOLVED] How to set different font in multi-lines cell? Reply with quote

Hello,
In one cell I must insert with macro text in two lines. This part is not a problem. Problem is how to set first line to has font 7.5 and second line font 2. (Please, do not ask me why I must doing in that way.) If somebody know some solution, please, help me.
Thanks in advance

Here is code for inserting two lines in one cell:
Code:
Sub InsertNewLine

dim oDocumentModel
dim oDocumentView
dim oDocumentFrame
dim cellString
dim first_line
dim second_line

    oDocumentModel = ThisComponent
    oDocumentView = oDocumentModel.getCurrentController()
    oDocumentFrame = oDocumentView.Frame
   
oSheet = ThisComponent.Sheets.getByIndex(0)
oCell = oSheet.getCellRangeByName ("B2")

first_line = "first line"
second_line = "second line"
cellString = first_line & CHR(10) & second_line
oCell.string = cellString

end sub   


Last edited by sevalav on Wed Oct 20, 2010 2:15 pm; edited 1 time in total
Back to top
View user's profile Send private message
DVezina
OOo Advocate
OOo Advocate


Joined: 29 Sep 2006
Posts: 248
Location: Orlando

PostPosted: Tue Oct 19, 2010 4:34 pm    Post subject: Reply with quote

Code:

Sub InsertNewLine

dim oDocumentModel
dim oDocumentView
dim oDocumentFrame
dim cellString
dim first_line
dim second_line

    oDocumentModel = ThisComponent
    oDocumentView = oDocumentModel.getCurrentController()
    oDocumentFrame = oDocumentView.Frame
   
oSheet = ThisComponent.Sheets.getByIndex(0)
oCell = oSheet.getCellRangeByName ("B2")
oCellText = oCell.getText()
oTextCursor = oCellText.createTextCursor()
oTextCursor.CharColor = 16724787
oTextCursor.setString("first line")
oTextCursor.GoToEnd(false)
oTextCursor.setString(Chr(10))
oTextCursor.GoToEnd(false)
oTextCursor.CharColor = 255
oTextCursor.setString("second line")

end sub     

Back to top
View user's profile Send private message
sevalav
OOo Enthusiast
OOo Enthusiast


Joined: 19 Sep 2009
Posts: 119

PostPosted: Wed Oct 20, 2010 2:14 pm    Post subject: Reply with quote

DVezina, thanks a lot! Its working!
Your code put different font color. For somebody who need to put different size of font in one multi-lines cell, look below:
Code:

Sub InsertNewLine2

dim oDocumentModel
dim oDocumentView
dim oDocumentFrame
dim cellString
dim first_line
dim second_line

    oDocumentModel = ThisComponent
    oDocumentView = oDocumentModel.getCurrentController()
    oDocumentFrame = oDocumentView.Frame
   
oSheet = ThisComponent.Sheets.getByIndex(0)
oCell = oSheet.getCellRangeByName ("B2")
oCellText = oCell.getText()
oTextCursor = oCellText.createTextCursor()
oTextCursor.CharHeight = 7.5
oTextCursor.setString("first line")
oTextCursor.GoToEnd(false)
oTextCursor.setString(Chr(10))
oTextCursor.GoToEnd(false)
oTextCursor.CharHeight = 2
oTextCursor.setString("second line")

end sub     
Back to top
View user's profile Send private message
DVezina
OOo Advocate
OOo Advocate


Joined: 29 Sep 2006
Posts: 248
Location: Orlando

PostPosted: Wed Oct 20, 2010 3:28 pm    Post subject: Reply with quote

Embarassed Don't know why I saw font color but I'm glad you figured it out.
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