| View previous topic :: View next topic |
| Author |
Message |
christopher23 General User

Joined: 25 Feb 2010 Posts: 19
|
Posted: Mon Mar 01, 2010 1:13 am Post subject: Changing property values of text |
|
|
Hello i'm trying to make my first line Heading 1 and my second line standard text. But somehow both lines are affected in the same way. They both turn out standard text or they both turn out as Heading 1.
| Code: |
pageStyleCollection = document.getStyleFamilies().getByName("PageStyles")
propertySet = pageStyleCollection.getByName("Standard")
propertySet.setPropertyValue("HeaderIsOn", True)
headerText = propertySet.getPropertyValue("HeaderText")
text = headerText.Text
headerHeading = text.createTextCursor()
headerHeading.setPropertyValue("ParaStyleName", "Heading 1")
headerHeading.setPropertyValue("CharHeight", 11)
headerHeading.setPropertyValue("CharColor", operator.getCharColor("61116a"))
headerText.insertString(headerHeading, "My First Line, Which should be Heading 1\n", False)
text2 = headerText.Text
headerLine = text2.createTextCursor()
headerLine.setPropertyValue("ParaStyleName", "Standard")
headerLine.setPropertyValue("CharHeight", 11)
headerLine.setPropertyValue("CharWeight", BOLD)
headerText.insertString(headerLine, "My Second Line, Which should be Standard text\n", False)
|
Could someone explain to me how this can be fixed? |
|
| Back to top |
|
 |
naurispunk Power User

Joined: 28 Oct 2009 Posts: 50
|
Posted: Tue Mar 02, 2010 8:50 am Post subject: |
|
|
First things first - i am not sure what language you are using but I rewrote your code in visual basic .net and it works (at the end of the post).
Only problem i got and this maybe your problem as well - Paragraphs must be seperated with valid Paragraph Break. In Visual Basic .NET I use constant vbCrLf. You seem to use "/n" so make sure that after you insert the first line you have 2 lines in header and also make sure that your cursor before inserting 2nd text is in second line (cursor.gottoEnd() might help). You have to do this bacause only one Paragraph Style can be applied to one paragraph.
| Code: | '' get the current current cursor(-=dabu view kursoru)
Dim xModel As unoidl.com.sun.star.frame.XModel = Me.XComponent
Dim xController As unoidl.com.sun.star.frame.XController = xModel.getCurrentController
Dim xViewCursorSupplier As XTextViewCursorSupplier = xController
Dim xViewCursor As XTextViewCursor = xViewCursorSupplier.getViewCursor
''http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Text/TextViewCursor
Dim xPageCursor As unoidl.com.sun.star.text.XPageCursor
xPageCursor = xViewCursor
''-=dabu lapu skaitu
Dim PagesCount As Integer
xPageCursor.jumpToLastPage()
PagesCount = xPageCursor.getPage()
For CurrentPageNumber As Integer = 1 To PagesCount
xPageCursor.jumpToPage(CurrentPageNumber)
'' get access to the properties of the current cursor and retrieve
'' name of the current pagestyle
Dim Props As XPropertySet
Props = xPageCursor
Dim PageStyleName As String
PageStyleName = Props.getPropertyValue("PageStyleName").Value
''next we search the StyleFamily entries for our current pagestyle (GetPageSetUp)
Dim xSupplier As XStyleFamiliesSupplier = XComponent
xSupplier = XComponent
Dim xFamilies As XNameAccess
xFamilies = xSupplier.getStyleFamilies()
Dim xFamily As XNameContainer
xFamily = xFamilies.getByName("PageStyles").Value
Dim xStyle As XStyle
xStyle = xFamily.getByName(PageStyleName).Value
''get the properties of the current page
Dim xStyleProps As XPropertySet
xStyleProps = DirectCast(xStyle, XPropertySet)
Dim HeaderIsOn As Boolean
HeaderIsOn = xStyleProps.getPropertyValue("HeaderIsOn").Value
''-=Galvene
If Not HeaderIsOn Then
xStyleProps.setPropertyValue("HeaderIsOn", New uno.Any(GetType(Boolean), True))
End If
Dim xHeaderText As XText
xHeaderText = xStyleProps.getPropertyValue("HeaderText").Value
'Dim xLineCursor As XLineCursor
'xLineCursor = xHeaderText.createTextCursor
''First line
Dim xCursor As unoidl.com.sun.star.text.XTextCursor
xCursor = xHeaderText.createTextCursor
xCursor.gotoEnd(False)
Dim CursorProps As XPropertySet
CursorProps = xCursor
CursorProps.setPropertyValue("ParaStyleName", New uno.Any(GetType(String), "Heading 1"))
CursorProps.setPropertyValue("CharHeight", New uno.Any(GetType(Integer), 11))
CursorProps.setPropertyValue("CharColor", New uno.Any(GetType(Integer), Color.Red.ToArgb))
xCursor.setString("My First Line, Which should be Heading " & [u]vbCrLf[/u])
''Second line
xCursor = xHeaderText.createTextCursorByRange(xHeaderText.getEnd)
xCursor.goRight(2, False)
CursorProps = xCursor
'' CursorProps.setPropertyValue("ParaStyleName", New uno.Any(GetType(String), "Standard"))
CursorProps.setPropertyValue("ParaStyleName", New uno.Any(GetType(String), "Standard"))
CursorProps.setPropertyValue("CharWeight", New uno.Any(GetType(Integer), 150))
CursorProps.setPropertyValue("CharColor", New uno.Any(GetType(Integer), Color.Green.ToArgb))
xCursor.setString("My Second Line, Which should be Standard text\n")
Next |
_________________ Few things I probably should have mentioned in my thread but forgot.
1) Im developing in Visual Basic .NET with vs2008
2) Im trying to integrate OO programs like writer, Calc, impress into .NET application
3) working with OO API since january 2010 |
|
| 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
|