How to use Words.dll to set Font style and paragraph style?

Hi, All,

I use the codes as follow to set font style and paragraph style in VB.net, but it doesn’t work. Why?

document = New Aspose.Words.Document(fileName)
builder = New DocumentBuilder(document)
builder.Bold = 1
builder.Italic = 0
builder.Underline = 0
font.StrikeThrough = 0
builder.Font.Color = LColor.BackColor
builder.Font.Name = FontName
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
builder.Write(headContent)
builder.Document.Save(dFile)

I expected to add new Headers to the doc, and set the header in center alignment with the fontsize=20,fontcolor=red,fontBold=true,Fontname=“Arial”. but this codes didn’t work, so that I cannot use Words.dll to customize the fontstyle and paragraphStyle. What is the correct codes to implement this ?

Thanks for your demo in advance.

Cheng

Hi Cheng,

Thanks for your inquiry. Please use following code example to achieve your requirements. Hope this helps you.

If you still face problem, please share your input and expected output documents here for our reference. We will then provide you more information about your query along with code.

Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
builder.Font.Size = 20
builder.Font.Color = Color.Red
builder.Font.Bold = True
builder.Font.Name = "Arial"
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
builder.Writeln("Header text")
doc.Save(MyDir + "Out v16.8.0.docx")