Class StyleCollection
Represents a collection of Style objects.
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Portable.dll
Syntax
public class StyleCollection : CollectionImpl, IStyleCollection, ICollectionBase, IEnumerable
Properties
FixedIndex13HasStyle
Gets or sets a value indicating whether the stylesheet has style at 13th index
Declaration
public bool FixedIndex13HasStyle { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True, if the stylesheet has style at 13th index(other than empty style), otherwise false |
Remarks
Reserved styles are applicable only for *.doc format
FixedIndex13StyleName
Gets or sets the name of the style at 13th index in the stylesheet
Declaration
public string FixedIndex13StyleName { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that represents the name of the style. |
Remarks
Reserved styles are applicable only for *.doc format
FixedIndex14HasStyle
Gets or sets a value indicating whether the stylesheet has style at 14th index
Declaration
public bool FixedIndex14HasStyle { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True, if the stylesheet has style at 14th index(other than empty style), otherwise false |
Remarks
Reserved styles are applicable only for *.doc format
FixedIndex14StyleName
Gets or sets the name of the style at 14th index in the stylesheet
Declaration
public string FixedIndex14StyleName { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that represents the name of the style. |
Remarks
Reserved styles are applicable only for *.doc format
Item[Int32]
Gets the Style at the specified index.
Declaration
public IStyle this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index of the style to get |
Property Value
Type | Description |
---|---|
IStyle | The Style at the specified index |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The index is not valid index in the StyleCollection |
Methods
Add(IStyle)
Adds the specified Style to collection.
Declaration
public int Add(IStyle style)
Parameters
Type | Name | Description |
---|---|---|
IStyle | style | The Style to be added to the styles collection. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the added Style. |
Examples
The following code example demonstrates how to add style to the document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Open an input Word template
WordDocument document = new WordDocument("Template.docx");
//Access the styles collection which contains paragraph and character styles in Word document
WParagraphStyle style = new WParagraphStyle(document);
//Specify the style name.
style.Name = "User_Defined_style";
//Specify the character properties for the style
style.CharacterFormat.Bold = true;
style.CharacterFormat.FontName = "Arial";
style.CharacterFormat.FontSize = 14;
//Specify the paragraph properties for the style
style.ParagraphFormat.BackColor = Color.LightGray;
style.ParagraphFormat.AfterSpacing = 18f;
style.ParagraphFormat.BeforeSpacing = 18f;
StyleCollection styleCollection = document.Styles as StyleCollection;
//Add the style to the document styles collection.
styleCollection.Add(style);
//Save and close the document
document.Save("Result.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Open an input Word template
Dim document As New WordDocument(inputFileName)
'Access the styles collection which contains paragraph and character styles in Word document
Dim style As New WParagraphStyle(document)
'Specify the style name.
style.Name = "User_Defined_style"
'Specify the character properties for the style
style.CharacterFormat.Bold = True
style.CharacterFormat.FontName = "Arial"
style.CharacterFormat.FontSize = 14
'Specify the paragraph properties for the style
style.ParagraphFormat.BackColor = Color.LightGray
style.ParagraphFormat.AfterSpacing = 18F
style.ParagraphFormat.BeforeSpacing = 18F
Dim styleCollection As StyleCollection = TryCast(document.Styles, StyleCollection)
'Add the style to the document styles collection.
styleCollection.Add(style)
'Save and close the document
document.Save(outputFileName, FormatType.Docx)
document.Close()
End Sub
FindById(Int32)
Finds a style specified by its style Id.
Declaration
public IStyle FindById(int styleId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | styleId | The integer that represents the Id of the style. |
Returns
Type | Description |
---|---|
IStyle | The IStyle object of specified Id |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The style Id is not valid in the StyleCollection |
FindByName(String)
Finds a first style in the collection with specified style name.
Declaration
public IStyle FindByName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string value that represents the name of the style to be found. |
Returns
Type | Description |
---|---|
IStyle | The IStyle object of specified name |
Examples
The following example illustrates how to find a style by its name and modify its character and paragraph formats.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Open an input Word template
WordDocument document = new WordDocument("Template.docx");
//Access the styles collection which contains paragraph and character styles in Word document
IStyleCollection styleCollection = document.Styles;
//Find the style with the name "Heading 1"
WParagraphStyle heading1ParagraphStyle = styleCollection.FindByName("Heading 1") as WParagraphStyle;
//Change the text color of style "Heading 1" as DarkBlue
heading1ParagraphStyle.CharacterFormat.TextColor = Color.DarkBlue;
//Change the first line indent of Paragraph as 36 points
heading1ParagraphStyle.ParagraphFormat.FirstLineIndent = 36;
document.Save("Result.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Open an input Word template
Dim document As New WordDocument(inputFileName)
'Access the styles collection which contains paragraph and character styles in Word document
Dim styleCollection As IStyleCollection = document.Styles
'Find the style with the name "Heading 1"
Dim heading1ParagraphStyle As WParagraphStyle = TryCast(styleCollection.FindByName("Heading 1"), WParagraphStyle)
'Change the text color of style "Heading 1" as DarkBlue
heading1ParagraphStyle.CharacterFormat.TextColor = Color.DarkBlue
'Change the first line indent of paragraph as 36 points
heading1ParagraphStyle.ParagraphFormat.FirstLineIndent = 36
document.Save(outputFileName, FormatType.Docx)
document.Close()
End Sub
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The style name is not valid in the StyleCollection |
FindByName(String, StyleType)
Finds a style in the collection specified by the style name and style type.
Declaration
public IStyle FindByName(string name, StyleType styleType)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string value that represents the name of the style to be found. |
StyleType | styleType | The StyleType of the specified style. |
Returns
Type | Description |
---|---|
IStyle | The IStyle object with the specified name. |
Examples
The following example illustrates how to find a style by its name and its type.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Open an input Word template
WordDocument document = new WordDocument("Template.docx");
//Access the styles collection which contains paragraph and character styles in Word document
IStyleCollection styleCollection = document.Styles;
//Find the style with the name "Heading 1"
WParagraphStyle heading1ParagraphStyle = styleCollection.FindByName("Heading 1", StyleType.ParagraphStyle) as WParagraphStyle;
//Change the text color of style "Heading 1" as DarkBlue
heading1ParagraphStyle.CharacterFormat.TextColor = Color.DarkBlue;
//Change the first line indent of Paragraph as 36 points
heading1ParagraphStyle.ParagraphFormat.FirstLineIndent = 36;
document.Save("Result.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Open an input Word template
Dim document As New WordDocument(inputFileName)
'Access the styles collection which contains paragraph and character styles in Word document
Dim styleCollection As IStyleCollection = document.Styles
'Find the style with the name "Heading 1"
Dim heading1ParagraphStyle As WParagraphStyle = TryCast(styleCollection.FindByName("Heading 1", StyleType.ParagraphStyle), WParagraphStyle)
'Change the text color of style "Heading 1" as DarkBlue
heading1ParagraphStyle.CharacterFormat.TextColor = Color.DarkBlue
'Change the first line indent of Paragraph as 36 points
heading1ParagraphStyle.ParagraphFormat.FirstLineIndent = 36
document.Save(outputFileName, FormatType.Docx)
document.Close()
End Sub
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The style name is not valid in the StyleCollection |