Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
ODF .NET
>
Tutorial
> Set paragraph style
The following example shows you how to set text font, underline and bold.
C# example
using System; using Independentsoft.Office.Odf; using Independentsoft.Office.Odf.Styles; namespace Sample { class Program { static void Main(string[] args) { TextDocument doc = new TextDocument(); Font arial = new Font(); arial.Name = "Arial"; arial.Family = "Arial"; arial.GenericFontFamily = GenericFontFamily.Swiss; arial.Pitch = FontPitch.Variable; doc.Fonts.Add(arial); ParagraphStyle style1 = new ParagraphStyle("MyStyle1"); style1.TextProperties.Font = "Arial"; style1.TextProperties.FontSize = new Size(12, Unit.Point); style1.TextProperties.FontWeight = FontWeight.Bold; style1.TextProperties.UnderlineType = UnderlineType.Single; doc.AutomaticStyles.Styles.Add(style1); Paragraph p1 = new Paragraph(); p1.Add("Hello"); p1.Style = "MyStyle1"; Paragraph p2 = new Paragraph(); p2.Add("World"); doc.Body.Add(p1); doc.Body.Add(p2); doc.Save("c:\\test\\output.odt", true); } } }
VB example
Imports System Imports Independentsoft.Office.Odf Imports Independentsoft.Office.Odf.Styles Module Module1 Sub Main(ByVal args() As String) Dim doc As New TextDocument() Dim arial As Font = New Font() arial.Name = "Arial" arial.Family = "Arial" arial.GenericFontFamily = GenericFontFamily.Swiss arial.Pitch = FontPitch.Variable doc.Fonts.Add(arial) Dim style1 As ParagraphStyle = New ParagraphStyle("MyStyle1") style1.TextProperties.Font = "Arial" style1.TextProperties.FontSize = New Size(12, Unit.Point) style1.TextProperties.FontWeight = FontWeight.Bold style1.TextProperties.UnderlineType = UnderlineType.Single doc.AutomaticStyles.Styles.Add(style1) Dim p1 As Paragraph = New Paragraph() p1.Add("Hello") p1.Style = "MyStyle1" Dim p2 As Paragraph = New Paragraph() p2.Add("World") doc.Body.Add(p1) doc.Body.Add(p2) doc.Save("c:\test\output.odt", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*