How to set paragraph style using .NET

Is it possible to append apiece of text to a paragraph without that piece of text (in this case the Speaker Name) taking on the style of the paragraph??

It looses the mxBodyTextSpeaker style unless I use the WriteLn method but this then takes a new line which I do not want.

I have enclosed the following piece of code as an example.

dbr.ParagraphFormat.Style = mxBodyTextSpeaker
dbr.Write("Speaker Name")
dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText
dbr.Writeln("Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1")

dbr.Writeln("Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1.")
dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText
dbr.Writeln("Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2")

dbr.ParagraphFormat.Style = mxBodyTextQuote
dbr.Writeln("Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote ")
dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText
dbr.Writeln("Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2.")

Hi Keith,

Thanks for your query. Please use the latest version of Aspose.Words for .NET 11.0.0. I have not found any issue with write method while using latest version. It would be great, If you share code related to
mxBodyTextSpeaker and mxBodyText for investigation purposes.

Thanks for the reply.

The issue with the write method is that I am unable to have two styles in the same paragraph.

I want the paragraph to have the speaker name then the speaker text wrapped in the mxBodyTextSpeaker then the mxBodyText to look like this:

Speaker Name: Speaker text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

is this possible? I have included the rest of the code as requested.

mxBodyText = newdoc.Styles.Add(AW.StyleType.Paragraph, "me Body Text")
With mxBodyText
.Font.Size = 10
.Font.Name = "ITC Franklin Gothic Book"
.ParagraphFormat.SpaceAfter = 12
End With

mxBodyTextSpeaker = newdoc.Styles.Add(AW.StyleType.Paragraph, "me Body Text - Speaker")
With mxBodyTextSpeaker
.Font.Size = 14
.Font.Bold = True
.Font.Name = "ITC Franklin Gothic Book"
.ParagraphFormat.SpaceAfter = 12
End With

mxBodyTextItalic = newdoc.Styles.Add(AW.StyleType.Paragraph, "me Body Text Italic")
With mxBodyTextItalic
.Font.Size = 22
.Font.Name = "ITC Franklin Gothic Book"
.ParagraphFormat.SpaceAfter = 12
End With

mxBodyTextQuote = newdoc.Styles.Add(AW.StyleType.Paragraph, "me Body Text Quote")
With mxBodyTextQuote
.Font.Size = 18
.Font.Name = "Bantang"
.ParagraphFormat.SpaceAfter = 12
End With

Hi Keith,

Please insert a paragraph beak after inserting text “Speaker Name”. Please use the following code snippet for your scenario.

mxBodyText = newdoc.Styles.Add(StyleType.Paragraph, "me Body Text")

With mxBodyText

.Font.Size = 10

.Font.Name = "ITC Franklin Gothic Book"

.ParagraphFormat.SpaceAfter = 12

End With

mxBodyTextSpeaker = newdoc.Styles.Add(StyleType.Paragraph, "me Body Text - Speaker")

With mxBodyTextSpeaker

.Font.Size = 14

.Font.Bold = True

.Font.Name = "ITC Franklin Gothic Book"

.ParagraphFormat.SpaceAfter = 12

End With

mxBodyTextItalic = newdoc.Styles.Add(StyleType.Paragraph, "me Body Text Italic")

With mxBodyTextItalic

.Font.Size = 22

.Font.Name = "ITC Franklin Gothic Book"

.ParagraphFormat.SpaceAfter = 12

End With

mxBodyTextQuote = newdoc.Styles.Add(StyleType.Paragraph, "me Body Text Quote")

With mxBodyTextQuote

.Font.Size = 18

.Font.Name = "Bantang"

.ParagraphFormat.SpaceAfter = 12

End With

dbr.ParagraphFormat.Style = mxBodyTextSpeaker

dbr.Write("Speaker Name")

dbr.InsertBreak(BreakType.ParagraphBreak)

dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText

dbr.Writeln("Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1")

dbr.Writeln("Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1.")

dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText

dbr.Writeln("Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2")

dbr.ParagraphFormat.Style = mxBodyTextQuote

dbr.Writeln("Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote ")

dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText

dbr.Writeln("Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2.")

newdoc.Save("D:\\Data\\Customers\\Asposeout.doc")

Thanks however by inserting the paragraph break the speaker name will be on a different line; I am looking to display the text inline as below?

Speaker Name: Speaker text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.v

Hi Keith,

Please use the following code snippet to use different fonts in one paragraph.

Dim newdoc As New Document()

Dim dbr As New DocumentBuilder(newdoc)

Dim mxBodyText As Style

Dim mxBodyTextSpeaker As Style

Dim mxBodyTextItalic As Style

Dim mxBodyTextQuote As Style

mxBodyText = newdoc.Styles.Add(StyleType.Paragraph, "me Body Text")

With mxBodyText

.Font.Size = 10

.Font.Name = "ITC Franklin Gothic Book"

.ParagraphFormat.SpaceAfter = 12

End With

mxBodyTextSpeaker = newdoc.Styles.Add(StyleType.Character, "me Body Text - Speaker")

With mxBodyTextSpeaker

.Font.Size = 14

.Font.Bold = True

.Font.Name = "ITC Franklin Gothic Book"

'.ParagraphFormat.SpaceAfter = 12

End With

mxBodyTextItalic = newdoc.Styles.Add(StyleType.Paragraph, "me Body Text Italic")

With mxBodyTextItalic

.Font.Size = 22

.Font.Name = "ITC Franklin Gothic Book"

.ParagraphFormat.SpaceAfter = 12

End With

mxBodyTextQuote = newdoc.Styles.Add(StyleType.Paragraph, "me Body Text Quote")

With mxBodyTextQuote

.Font.Size = 18

.Font.Name = "Bantang"

.ParagraphFormat.SpaceAfter = 12

End With

Dim run As New Run(newdoc)

run.Text = "Speaker Name"

run.Font.Style = mxBodyTextSpeaker

dbr.InsertNode(run)

dbr.ParagraphFormat.Style = mxBodyText

dbr.Writeln("Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1")

dbr.Writeln("Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1 Para 1.")

dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText

dbr.Writeln("Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2")

dbr.ParagraphFormat.Style = mxBodyTextQuote

dbr.Writeln("Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote Quote ")

dbr.ParagraphFormat.ClearFormatting()

dbr.ParagraphFormat.Style = mxBodyText

dbr.Writeln("Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2 Para 2.")

newdoc.Save("D:\\Asposeout.doc")

That works great, many thanks.