Class WSection
Represents the section of a Word document which contains header, footer, text body, etc.
Inheritance
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.NET.dll
Syntax
public class WSection : WidgetContainer, IXDLSSerializable, IWSection, ICompositeEntity, IEntity, IWidgetContainer, IWidget
Constructors
WSection(IWordDocument)
Initializes a new instance of the WSection class with the IWordDocument instance.
Declaration
public WSection(IWordDocument doc)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | doc | The IWordDocument instance. |
Fields
m_internalData
Declaration
protected byte[] m_internalData
Field Value
Type |
---|
System.Byte[] |
Properties
Body
Gets the section body. Read-only.
Declaration
public WTextBody Body { get; }
Property Value
Type | Description |
---|---|
WTextBody | The WTextBody of the current section. |
BreakCode
Gets or sets section break code of the current section.
Declaration
public SectionBreakCode BreakCode { get; set; }
Property Value
Type | Description |
---|---|
SectionBreakCode | The SectionBreakCode member that specifies the break code. |
ChildEntities
Gets the child elements of the section. Read-only.
Declaration
public EntityCollection ChildEntities { get; }
Property Value
Type | Description |
---|---|
EntityCollection | The collection of child elements. |
Columns
Gets the collection of columns which logically divide page on many printing or publishing areas. Read-only.
Declaration
public ColumnCollection Columns { get; }
Property Value
Type | Description |
---|---|
ColumnCollection | The collection of columns in the section. |
EntityType
Gets the type of the entity. Read-only.
Declaration
public override EntityType EntityType { get; }
Property Value
Type | Description |
---|---|
EntityType | The EntityType of the current item. |
Overrides
HeadersFooters
Gets headers and footers of the current section. Read-only.
Declaration
public WHeadersFooters HeadersFooters { get; }
Property Value
Type | Description |
---|---|
WHeadersFooters | The WHeadersFooters instance that specifies current section header, footer. |
PageSetup
Gets the page setup of the current section. Read-only.
Declaration
public WPageSetup PageSetup { get; }
Property Value
Type | Description |
---|---|
WPageSetup | The WPageSetup of the current section. |
Paragraphs
Gets the paragraphs in the current section. Read-only.
Declaration
public IWParagraphCollection Paragraphs { get; }
Property Value
Type | Description |
---|---|
IWParagraphCollection | The IWParagraphCollection that represents the collection of IWParagraph in the section. |
ProtectForm
Gets or sets a value indicating whether to allow editing of form fields in the section.
Declaration
public bool ProtectForm { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if to allow editing of form fields; otherwise, false. |
Tables
Gets the tables in the current section. Read-only.
Declaration
public IWTableCollection Tables { get; }
Property Value
Type | Description |
---|---|
IWTableCollection | The IWTableCollection that represents the collection of IWTable in the section. |
WidgetCollection
Returns the entity collection.
Declaration
protected override IEntityCollectionBase WidgetCollection { get; }
Property Value
Type | Description |
---|---|
IEntityCollectionBase | The collection of entities in the text body. |
Overrides
Methods
AddColumn(Single, Single)
Adds a new Column to the section.
Declaration
public Column AddColumn(float width, float spacing)
Parameters
Type | Name | Description |
---|---|---|
System.Single | width | The float that specifies the width of the column. |
System.Single | spacing | The float that specifies the spacing between the columns. |
Returns
Type | Description |
---|---|
Column | The reference to the newly added Column object. |
Examples
The following example illustrates how to have multiple columns in a section.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add the section into Word document
IWSection section = document.AddSection();
//Add the column into the section
section.AddColumn(150, 20);
//Add the column into the section
section.AddColumn(150, 20);
//Add the column into the section
section.AddColumn(150, 20);
//Add a paragraph to created section
IWParagraph paragraph = section.AddParagraph();
//Add a paragraph to created section
paragraph = section.AddParagraph();
paragraph.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum Turpis facilisis vitae consequat, cum a a,turpis dui consequat massa in dolor per, felis non amet.Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula";
//Append the text to the created paragraph
paragraph.AppendText(paragraph.Text);
//Add the column breaks
paragraph.AppendBreak(BreakType.ColumnBreak);
//Add a paragraph to created section
paragraph = section.AddParagraph();
//Append the text to the created paragraph
paragraph.AppendText(paragraph.Text);
//Add the column breaks
paragraph.AppendBreak(BreakType.ColumnBreak);
//Add a paragraph to created section
paragraph = section.AddParagraph();
//Append the text to the created paragraph
paragraph.AppendText(paragraph.Text);
//Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add the section into Word document
Dim section As IWSection = document.AddSection()
'Add the column into the section
section.AddColumn(150, 20)
'Add the column into the section
section.AddColumn(150, 20)
'Add the column into the section
section.AddColumn(150, 20)
'Add a paragraph to created section
Dim paragraph As IWParagraph = section.AddParagraph()
'Add a paragraph to created section
paragraph = section.AddParagraph()
Dim paraText As String = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum Turpis facilisis vitae consequat, cum a a,turpis dui consequat massa in dolor per, felis non amet.Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula"
'Append the text to the created paragraph
paragraph.AppendText(paraText)
'Add the column breaks
paragraph.AppendBreak(BreakType.ColumnBreak)
'Add a paragraph to created section
paragraph = section.AddParagraph()
'Append the text to the created paragraph
paragraph.AppendText(paraText)
'Add the column breaks
paragraph.AppendBreak(BreakType.ColumnBreak)
'Add a paragraph to created section
paragraph = section.AddParagraph()
'Append the text to the created paragraph
paragraph.AppendText(paraText)
'Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AddParagraph()
Adds the IWParagraph to the section body.
Declaration
public IWParagraph AddParagraph()
Returns
Type | Description |
---|---|
IWParagraph | The reference to the newly created paragraph. |
Examples
The following example illustrates how to add a paragraph to the section.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Gets the first section in the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("First paragraph in section");
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Gets the first section in the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("First paragraph in section")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AddTable()
Adds the IWTable to the section body.
Declaration
public IWTable AddTable()
Returns
Type | Description |
---|---|
IWTable | The reference to the newly created table. |
Examples
The following example illustrates how to add a table to the section.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Gets the first section in the document
IWSection section = document.AddSection();
//Add new table to the section
IWTable table = section.AddTable();
//Set rows and columns count
table.ResetCells(2, 2);
//Add contents to the table
IWParagraph paragraph = table[0, 0].AddParagraph();
paragraph.AppendText("Apple");
paragraph = table[0, 1].AddParagraph();
paragraph.AppendText("Red");
paragraph = table[1, 0].AddParagraph();
paragraph.AppendText("Banana");
paragraph = table[1, 1].AddParagraph();
paragraph.AppendText("Yellow");
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Gets the first section in the document
Dim section As IWSection = document.AddSection()
'Add new table to the section
Dim table As IWTable = section.AddTable()
'Set rows and columns count
table.ResetCells(2, 2)
'Add contents to the table
Dim paragraph As IWParagraph = table(0, 0).AddParagraph()
paragraph.AppendText("Apple")
paragraph = table(0, 1).AddParagraph()
paragraph.AppendText("Red")
paragraph = table(1, 0).AddParagraph()
paragraph.AppendText("Banana")
paragraph = table(1, 1).AddParagraph()
paragraph.AppendText("Yellow")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Clone()
Creates a duplicate copy of the current section.
Declaration
public WSection Clone()
Returns
Type | Description |
---|---|
WSection | The reference to the newly created section. |
CloneImpl()
Creates a duplicate copy of the section.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object | An object that can be casted as WSection. |
Overrides
CreateLayoutInfo()
Create layout information.
Declaration
protected override void CreateLayoutInfo()
Overrides
InitXDLSHolder()
Registers child objects in XDSL holder.
Declaration
protected override void InitXDLSHolder()
Overrides
MakeColumnsEqual()
Makes all columns in the current section to be of equal width.
Declaration
public void MakeColumnsEqual()
Examples
The following example illustrates how to have make the columns to be of equal width in a section.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument("Sample.docx");
//Gets the first section in the document
IWSection section = document.Sections[0];
//Make the columns to be of equal width
section.MakeColumnsEqual();
//Save and close the document
document.Save("Result.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument("Sample.docx")
'Gets the first section in the document
Dim section As IWSection = document.Sections(0)
'Make the columns to be of equal width
section.MakeColumnsEqual()
'Save and close the document
document.Save("Result.docx", FormatType.Docx)
document.Close()
End Sub
ReadXmlAttributes(IXDLSAttributeReader)
Reads object data from xml attributes.
Declaration
protected override void ReadXmlAttributes(IXDLSAttributeReader reader)
Parameters
Type | Name | Description |
---|---|---|
IXDLSAttributeReader | reader | The IXDLSAttributeReader object. |
Overrides
ReadXmlContent(IXDLSContentReader)
Reads object data from xml attributes.
Declaration
protected override bool ReadXmlContent(IXDLSContentReader reader)
Parameters
Type | Name | Description |
---|---|---|
IXDLSContentReader | reader | The IXDLSContentReader object. |
Returns
Type | Description |
---|---|
System.Boolean | The value indicating the presence of xml content. |
Overrides
WriteXmlAttributes(IXDLSAttributeWriter)
Writes object data as xml attributes.
Declaration
protected override void WriteXmlAttributes(IXDLSAttributeWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IXDLSAttributeWriter | writer | The IXDLSAttributeWriter object. |
Overrides
WriteXmlContent(IXDLSContentWriter)
Writes object data as inside xml element.
Declaration
protected override void WriteXmlContent(IXDLSContentWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IXDLSContentWriter | writer | The IXDLSContentWriter object. |