| View previous topic :: View next topic |
| Author |
Message |
sevalav OOo Enthusiast

Joined: 19 Sep 2009 Posts: 119
|
Posted: Tue Oct 19, 2010 2:13 pm Post subject: [SOLVED] How to set different font in multi-lines cell? |
|
|
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 |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Tue Oct 19, 2010 4:34 pm Post subject: |
|
|
| 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 |
|
 |
sevalav OOo Enthusiast

Joined: 19 Sep 2009 Posts: 119
|
Posted: Wed Oct 20, 2010 2:14 pm Post subject: |
|
|
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 |
|
 |
DVezina OOo Advocate

Joined: 29 Sep 2006 Posts: 248 Location: Orlando
|
Posted: Wed Oct 20, 2010 3:28 pm Post subject: |
|
|
Don't know why I saw font color but I'm glad you figured it out. |
|
| Back to top |
|
 |
|