Interface IWParagraph
Represents a paragraph inside a Section.
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.UWP.dll
Syntax
public interface IWParagraph : ITextBodyItem, IStyleHolder, ICompositeEntity, IEntity
Properties
BreakCharacterFormat
Gets the character format for the break symbol. Read-only.
Declaration
WCharacterFormat BreakCharacterFormat { get; }
Property Value
Type | Description |
---|---|
WCharacterFormat | The WCharacterFormat of the paragraph. |
EnableStyleSeparator
Gets or sets a value indicating whether the paragraph mark is treated as special hidden and it allows Microsoft Word to join paragraphs formatted using different paragraph styles.
Declaration
bool EnableStyleSeparator { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the paragraph mark is treated as special hidden; otherwise, false. |
IsEndOfDocument
Gets a value indicating whether the current paragraph is end of document. Read-only.
Declaration
bool IsEndOfDocument { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if this paragraph is end of document; otherwise, false. |
IsEndOfSection
Gets a value indicating whether the current paragraph is end of the section. Read-only.
Declaration
bool IsEndOfSection { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if this paragraph is end of section; otherwise false. |
IsInCell
Gets a value indicating whether the current paragraph is in cell. Read-only.
Declaration
bool IsInCell { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if this paragraph is in cell; otherwise, false. |
Item[Int32]
Gets the paragraph item at the specified index. Read-only.
Declaration
ParagraphItem this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index of the item to get from the collection. |
Property Value
Type | Description |
---|---|
ParagraphItem | The ParagraphItem at the specified index. |
Items
Gets the paragraph format of the current paragraph. Read-only.
Declaration
ParagraphItemCollection Items { get; }
Property Value
Type | Description |
---|---|
ParagraphItemCollection | The WParagraphFormat of the paragraph. |
ListFormat
Gets the format for the list in the paragraph. Read-only.
Declaration
WListFormat ListFormat { get; }
Property Value
Type | Description |
---|---|
WListFormat | The WListFormat of the list in the paragraph. |
ListString
Gets a string that represent the appearance of the list value of the paragraph.
Declaration
string ListString { get; }
Property Value
Type | Description |
---|---|
System.String | The string that represents a string value of the list of the paragraph. Default value is string.Empty |
Remarks
This property holds the static string of the list value recently calculated while saving the document as Text. It is not updated automatically for each modification done in the document. Hence, you should either invoke WordDocument.GetText() method or save the document as Text, to get the actual list value from this property. For a picture bulleted list, this property is not valid and will return string.Empty.
Examples
The following example illustrates how to get a numeric string value of the list paragraph.
// Loads an existing Word document into DocIO instance.
WordDocument document = new WordDocument("Template.docx");
//Gets the document text
document.GetText();
// Gets a numeric string value of the numbering list paragraph.
String listString = document.LastParagraph.ListString;
// Saves the document in the given name and format.
document.Save("Document.docx", FormatType.Docx);
// Releases the resources occupied by WordDocument instance.
document.Close();
' Loads an existing Word document into DocIO instance.
Dim document As WordDocument = New WordDocument("Template.docx")
' Gets the document text.
document.GetText()
' Gets a numeric string value of the numbering list paragraph
Dim listString As String = document.LastParagraph.ListString
' Saves the document in the given name and format.
document.Save("Document.docx", FormatType.Docx)
' Releases the resources occupied by WordDocument instance.
document.Close()
ParagraphFormat
Gets the paragraph format.
Declaration
WParagraphFormat ParagraphFormat { get; }
Property Value
Type |
---|
WParagraphFormat |
StyleName
Gets the name of the style applied to the current paragraph. Read-only.
Declaration
string StyleName { get; }
Property Value
Type | Description |
---|---|
System.String | The string that represents the style name. |
Text
Gets or sets text of the paragraph.
Declaration
string Text { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that represents the text. |
Remarks
All the internal formatting will be cleared when new text is set.
Methods
AppendBookmarkEnd(String)
Appends end of the bookmark with specified name to the paragraph.
Declaration
BookmarkEnd AppendBookmarkEnd(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string specifying the bookmark name. |
Returns
Type | Description |
---|---|
BookmarkEnd | The BookmarkEnd instance that represents the newly added bookmark end. |
Examples
The following example illustrates how to add a bookmark to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create an instance of WordDocument class (Empty Word Document)
WordDocument document = new WordDocument();
//Add a new section into the Word Document
IWSection section = document.AddSection();
//Add a new paragraph into Word document and append text into paragraph
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Northwind Database");
paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
//Add a paragraph into section
paragraph = section.AddParagraph();
//Add a new bookmark start into paragraph with name "Northwind"
paragraph.AppendBookmarkStart("Northwind");
//Add a text between the bookmark start and end into paragraph
paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases.");
//Add a new bookmark end into paragraph with name " Northwind "
paragraph.AppendBookmarkEnd("Northwind");
//Add a text after the bookmark end
paragraph.AppendText(" Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.");
//Save the document in the given name and format
document.Save("Bookmarks.docx", FormatType.Docx);
//Release the resources occupied by WordDocument instance
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create an instance of WordDocument class (Empty Word Document)
Dim document As New WordDocument()
'Add a new section into the Word Document
Dim section As IWSection = document.AddSection()
'Add a new paragraph into Word document and append text into paragraph
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Northwind Database")
paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center
'Add a paragraph into section
paragraph = section.AddParagraph()
'Add a new bookmark start into paragraph with name "Northwind"
paragraph.AppendBookmarkStart("Northwind")
'Add a text between the bookmark start and end into paragraph
paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases.")
'Add a new bookmark end into paragraph with name " Northwind "
paragraph.AppendBookmarkEnd("Northwind")
'Add a text after the bookmark end
paragraph.AppendText(" Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.")
'Save the document in the given name and format
document.Save("Bookmarks.docx", FormatType.Docx)
'Release the resources occupied by WordDocument instance
document.Close()
End Sub
AppendBookmarkStart(String)
Appends start of the bookmark with specified name to the paragraph.
Declaration
BookmarkStart AppendBookmarkStart(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string specifying the bookmark name. |
Returns
Type | Description |
---|---|
BookmarkStart | The BookmarkStart instance that represents the newly added bookmark start. |
Examples
The following example illustrates how to add a bookmark to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create an instance of WordDocument class (Empty Word Document)
WordDocument document = new WordDocument();
//Add a new section into the Word Document
IWSection section = document.AddSection();
//Add a new paragraph into Word document and append text into paragraph
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Northwind Database");
paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
//Add a paragraph into section
paragraph = section.AddParagraph();
//Add a new bookmark start into paragraph with name "Northwind"
paragraph.AppendBookmarkStart("Northwind");
//Add a text between the bookmark start and end into paragraph
paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases.");
//Add a new bookmark end into paragraph with name " Northwind "
paragraph.AppendBookmarkEnd("Northwind");
//Add a text after the bookmark end
paragraph.AppendText(" Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.");
//Save the document in the given name and format
document.Save("Bookmarks.docx", FormatType.Docx);
//Release the resources occupied by WordDocument instance
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create an instance of WordDocument class (Empty Word Document)
Dim document As New WordDocument()
'Add a new section into the Word Document
Dim section As IWSection = document.AddSection()
'Add a new paragraph into Word document and append text into paragraph
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Northwind Database")
paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center
'Add a paragraph into section
paragraph = section.AddParagraph()
'Add a new bookmark start into paragraph with name "Northwind"
paragraph.AppendBookmarkStart("Northwind")
'Add a text between the bookmark start and end into paragraph
paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases.")
'Add a new bookmark end into paragraph with name " Northwind "
paragraph.AppendBookmarkEnd("Northwind")
'Add a text after the bookmark end
paragraph.AppendText(" Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.")
'Save the document in the given name and format
document.Save("Bookmarks.docx", FormatType.Docx)
'Release the resources occupied by WordDocument instance
document.Close()
End Sub
AppendBreak(BreakType)
Appends break of the specified type to end of the paragraph.
Declaration
Break AppendBreak(BreakType breakType)
Parameters
Type | Name | Description |
---|---|---|
BreakType | breakType | The BreakType member that specifies the type of break. |
Returns
Type | Description |
---|---|
Break | The Break instance that represents the newly added break. |
Examples
The following example illustrates how to add a break to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Before line break");
//Add line break to the paragraph
paragraph.AppendBreak(BreakType.LineBreak);
paragraph.AppendText("After line break");
IWParagraph pageBreakPara = section.AddParagraph();
pageBreakPara.AppendText("Before page break");
//Add page break to the paragraph
pageBreakPara.AppendBreak(BreakType.PageBreak);
pageBreakPara.AppendText("After page break");
IWSection secondSection = document.AddSection();
//Add columns to the section
secondSection.AddColumn(100, 2);
secondSection.AddColumn(100, 2);
IWParagraph columnBreakPara = secondSection.AddParagraph();
columnBreakPara.AppendText("Before column break");
//Add column break to the paragraph
columnBreakPara.AppendBreak(BreakType.ColumnBreak);
columnBreakPara.AppendText("After column break");
//Save and Close the 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 new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Before line break")
'Add line break to the paragraph
paragraph.AppendBreak(BreakType.LineBreak)
paragraph.AppendText("After line break")
Dim pageBreakPara As IWParagraph = section.AddParagraph()
pageBreakPara.AppendText("Before page break")
'Add page break to the paragraph
pageBreakPara.AppendBreak(BreakType.PageBreak)
pageBreakPara.AppendText("After page break")
Dim secondSection As IWSection = document.AddSection()
'Add columns to the section
secondSection.AddColumn(100, 2)
secondSection.AddColumn(100, 2)
Dim columnBreakPara As IWParagraph = secondSection.AddParagraph()
columnBreakPara.AppendText("Before column break")
'Add column break to the paragraph
columnBreakPara.AppendBreak(BreakType.ColumnBreak)
columnBreakPara.AppendText("After column break")
'Save and Close the document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AppendChart(Stream, Int32, String, Single, Single)
Appends chart to the end of the paragraph from the excel file with specified sheet number, range of data, width, and height.
Declaration
WChart AppendChart(Stream excelStream, int sheetNumber, string dataRange, float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | excelStream | The excel stream that has data for chart [Excel stream should be "*.xlsx" format]. |
System.Int32 | sheetNumber | The integer represents the worksheet number that has data for chart. |
System.String | dataRange | The string represents the data range in the worksheet from which the chart is to be created. |
System.Single | width | The float that represents the width for chart. |
System.Single | height | The float that represents the height for chart. |
Returns
Type | Description |
---|---|
WChart | The WChart instance that represents the newly added chart. |
Remarks
This method is not supported in Silverlight, WinRT, Windows Phone, Universal, Universal Windows Platform and Xamarin applications.
Examples
The following example illustrates how to append new chart to the paragraph using the excel stream.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add section to the document
IWSection sec = document.AddSection();
//Add paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Load the excel file as stream
Stream excelStream = File.OpenRead("Excel_Template.xlsx");
//Create and Append chart to the paragraph with excel stream as parameter
WChart chart = paragraph.AppendChart(excelStream, 1, "B2:C6", 470, 300);
//Set chart type and title
chart.ChartType = OfficeChartType.Column_Clustered;
chart.ChartTitle = "Purchase Details";
chart.ChartTitleArea.FontName = "Calibri";
chart.ChartTitleArea.Size = 14;
chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None;
//Set name to chart series
chart.Series[0].Name = "Sum of Purchases";
chart.Series[1].Name = "Sum of Future Expenses";
chart.PrimaryCategoryAxis.Title = "Products";
chart.PrimaryValueAxis.Title = "In Dollars";
//Set position of legend
chart.Legend.Position = OfficeLegendPosition.Bottom;
//Save the document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add section to the document
Dim sec As IWSection = document.AddSection()
'Add paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Load the excel file as stream
Dim excelStream As Stream = File.OpenRead("Excel_Template.xlsx")
'Create and Append chart to the paragraph with excel stream as parameter
Dim chart As WChart = paragraph.AppendChart(excelStream, 1, "B2:C6", 470, 300)
'Set chart type and title
chart.ChartType = OfficeChartType.Column_Clustered
chart.ChartTitle = "Purchase Details"
chart.ChartTitleArea.FontName = "Calibri"
chart.ChartTitleArea.Size = 14
chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None
'Set name to chart series
chart.Series(0).Name = "Sum of Purchases"
chart.Series(1).Name = "Sum of Future Expenses"
chart.PrimaryCategoryAxis.Title = "Products"
chart.PrimaryValueAxis.Title = "In Dollars"
'Set position of legend
chart.Legend.Position = OfficeLegendPosition.Bottom
'Save the document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendChart(Object[][], Single, Single)
Appends a chart to the end of the paragraph with the specified data, width and height.
Declaration
WChart AppendChart(object[][] data, float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.Object[][] | data | The two-dimensional System.Object array that specifies the data for chart. |
System.Single | width | The float that represents the width for chart. |
System.Single | height | The float that represents the height for chart. |
Returns
Type | Description |
---|---|
WChart | The WChart instance that represents the newly added chart. |
Remarks
This method is not supported in Silverlight, WinRT, Windows Phone, Universal, Universal Windows Platform and Xamarin applications.
Examples
The following example illustrates how to append new chart to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add section to the document
IWSection sec = document.AddSection();
//Add paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Input data for chart
object[][] data = new object[6][];
for (int i = 0; i < 6; i++)
data[i] = new object[3];
data[0][0] = "";
data[1][0] = "Gravad lax";
data[2][0] = "Louisiana Hot spiced Okara";
data[3][0] = "Mascarpone Fabioli";
data[4][0] = "Wimmers gute SemmelKnodel";
data[5][0] = "Maxilaku";
data[0][1] = "Sum of Purchases";
data[1][1] = 286;
data[2][1] = 680;
data[3][1] = 288;
data[4][1] = 200;
data[5][1] = 731;
data[0][2] = "Sum of Future Expenses";
data[1][2] = 1300;
data[2][2] = 700;
data[3][2] = 1280;
data[4][2] = 1200;
data[5][2] = 2660; ///
//Create and Append chart to the paragraph
WChart chart = paragraph.AppendChart(data, 470, 300);
//Set chart type and title
chart.ChartTitle = "Purchase Details";
chart.ChartTitleArea.FontName = "Calibri";
chart.ChartTitleArea.Size = 14;
chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None;
//Set series type
chart.Series[0].SerieType = OfficeChartType.Line_Markers;
chart.Series[1].SerieType = OfficeChartType.Bar_Clustered;
chart.PrimaryCategoryAxis.Title = "Products";
chart.PrimaryValueAxis.Title = "In Dollars";
//Set position of legend
chart.Legend.Position = OfficeLegendPosition.Bottom;
//Save the document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add section to the document
Dim sec As IWSection = document.AddSection()
'Add paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Input data for chart
Dim data As Object()() = New Object(5)() {}
For i As Integer = 0 To 5
data(i) = New Object(2) {}
Next
data(0)(0) = ""
data(1)(0) = "Gravad lax"
data(2)(0) = "Louisiana Hot spiced Okara"
data(3)(0) = "Mascarpone Fabioli"
data(4)(0) = "Wimmers gute SemmelKnodel"
data(5)(0) = "Maxilaku"
data(0)(1) = "Sum of Purchases"
data(1)(1) = 286
data(2)(1) = 680
data(3)(1) = 288
data(4)(1) = 200
data(5)(1) = 731
data(0)(2) = "Sum of Future Expenses"
data(1)(2) = 1300
data(2)(2) = 700
data(3)(2) = 1280
data(4)(2) = 1200
data(5)(2) = 2660
'Create and Append chart to the paragraph
Dim chart As WChart = paragraph.AppendChart(data, 470, 300)
'Set chart type and title
chart.ChartTitle = "Purchase Details"
chart.ChartTitleArea.FontName = "Calibri"
chart.ChartTitleArea.Size = 14
chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None
'Set series type
chart.Series(0).SerieType = OfficeChartType.Line_Markers
chart.Series(1).SerieType = OfficeChartType.Bar_Clustered
chart.PrimaryCategoryAxis.Title = "Products"
chart.PrimaryValueAxis.Title = "In Dollars"
'Set position of legend
chart.Legend.Position = OfficeLegendPosition.Bottom
'Save the document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendChart(Single, Single)
Appends chart to the end of the paragraph with the specified width and height.
Declaration
WChart AppendChart(float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.Single | width | The float that represents the width for chart. |
System.Single | height | The float that represents the height for chart. |
Returns
Type | Description |
---|---|
WChart | The WChart instance that represents the newly added chart. |
Remarks
This method is not supported in Silverlight, WinRT, Windows Phone, Universal, Universal Windows Platform and Xamarin applications.
Examples
The following example illustrates how to append new chart to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add section to the document
IWSection sec = document.AddSection();
//Add paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Create and Append chart to the paragraph
WChart chart = paragraph.AppendChart(446, 270);
//Set chart type
chart.ChartType = OfficeChartType.Pie;
//Set chart title
chart.ChartTitle = "Best Selling Products";
chart.ChartTitleArea.FontName = "Calibri";
chart.ChartTitleArea.Size = 14;
//Set data for chart
chart.ChartData.SetValue(1, 1, "");
chart.ChartData.SetValue(1, 2, "Sales");
chart.ChartData.SetValue(2, 1, "Cote de Blaye");
chart.ChartData.SetValue(2, 2, 141.396);
chart.ChartData.SetValue(3, 1, "Thuringer Rostbratwurst");
chart.ChartData.SetValue(3, 2, 80.368);
chart.ChartData.SetValue(4, 1, "Raclette Courdavault");
chart.ChartData.SetValue(4, 2, 71.155);
chart.ChartData.SetValue(5, 1, "Tarte au sucre");
chart.ChartData.SetValue(5, 2, 47.234);
chart.ChartData.SetValue(6, 1, "Camembert Pierrot");
chart.ChartData.SetValue(6, 2, 46.825);
chart.ChartData.SetValue(7, 1, "Gnocchi di nonna Alice");
chart.ChartData.SetValue(7, 2, 42.593);
chart.ChartData.SetValue(8, 1, "Manjimup Dried Apples");
chart.ChartData.SetValue(8, 2, 41.819);
chart.ChartData.SetValue(9, 1, "Alice Mutton");
chart.ChartData.SetValue(9, 2, 32.698);
chart.ChartData.SetValue(10, 1, "Carnarvon Tigers");
chart.ChartData.SetValue(10, 2, 29.171);
chart.ChartData.SetValue(11, 1, "R�ssle Sauerkraut.");
chart.ChartData.SetValue(11, 2, 25.696);
//Create a new chart series with the name �Sales�
IOfficeChartSerie pieSeries = chart.Series.Add("Sales");
pieSeries.Values = chart.ChartData[2, 2, 11, 2];
//Set data label
pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside;
//Set background color
chart.ChartArea.Fill.ForeColor = Color.FromArgb(242, 242, 242);
chart.PlotArea.Fill.ForeColor = Color.FromArgb(242, 242, 242);
chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None;
//Set category labels
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 11, 1];
//Save the document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add section to the document
Dim sec As IWSection = document.AddSection()
'Add paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Create and Append chart to the paragraph
Dim chart As WChart = paragraph.AppendChart(446, 270)
'Set chart type
chart.ChartType = OfficeChartType.Pie
'Set chart title
chart.ChartTitle = "Best Selling Products"
chart.ChartTitleArea.FontName = "Calibri"
chart.ChartTitleArea.Size = 14
'Set data for chart
chart.ChartData.SetValue(1, 1, "")
chart.ChartData.SetValue(1, 2, "Sales")
chart.ChartData.SetValue(2, 1, "Cote de Blaye")
chart.ChartData.SetValue(2, 2, 141.396)
chart.ChartData.SetValue(3, 1, "Thuringer Rostbratwurst")
chart.ChartData.SetValue(3, 2, 80.368)
chart.ChartData.SetValue(4, 1, "Raclette Courdavault")
chart.ChartData.SetValue(4, 2, 71.155)
chart.ChartData.SetValue(5, 1, "Tarte au sucre")
chart.ChartData.SetValue(5, 2, 47.234)
chart.ChartData.SetValue(6, 1, "Camembert Pierrot")
chart.ChartData.SetValue(6, 2, 46.825)
chart.ChartData.SetValue(7, 1, "Gnocchi di nonna Alice")
chart.ChartData.SetValue(7, 2, 42.593)
chart.ChartData.SetValue(8, 1, "Manjimup Dried Apples")
chart.ChartData.SetValue(8, 2, 41.819)
chart.ChartData.SetValue(9, 1, "Alice Mutton")
chart.ChartData.SetValue(9, 2, 32.698)
chart.ChartData.SetValue(10, 1, "Carnarvon Tigers")
chart.ChartData.SetValue(10, 2, 29.171)
chart.ChartData.SetValue(11, 1, "R�ssle Sauerkraut.")
'Create a new chart series with the name �Sales�
Dim pieSeries As IOfficeChartSerie = chart.Series.Add("Sales")
pieSeries.Values = chart.ChartData(2, 2, 11, 2)
'Set data label
pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsValue = True
pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside
'Set background color
chart.ChartArea.Fill.ForeColor = Color.FromArgb(242, 242, 242)
chart.PlotArea.Fill.ForeColor = Color.FromArgb(242, 242, 242)
chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None
'Set category labels
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData(2, 1, 11, 1)
'Save the document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendCheckBox()
Appends the check box to the paragraph.
Declaration
WCheckBox AppendCheckBox()
Returns
Type | Description |
---|---|
WCheckBox | The WCheckBox instance that represents the newly added checkbox. |
Examples
The following example illustrates how to add a checkbox to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
paragraph.AppendText("Gender\t");
//Append new Checkbox
WCheckBox checkbox = paragraph.AppendCheckBox();
checkbox.Checked = false;
//Set Checkbox size
checkbox.CheckBoxSize = 10;
checkbox.CalculateOnExit = true;
//Set help text
checkbox.Help = "Help text";
paragraph.AppendText("Male\t");
checkbox = paragraph.AppendCheckBox();
checkbox.Checked = false;
checkbox.CheckBoxSize = 10;
checkbox.CalculateOnExit = true;
paragraph.AppendText("Female");
//Save the Word document
document.Save("Checkbox.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As WParagraph = TryCast(section.AddParagraph(), WParagraph)
paragraph.AppendText("Gender" & vbTab)
'Append new Checkbox
Dim checkbox As WCheckBox = paragraph.AppendCheckBox()
checkbox.Checked = False
'Set Checkbox size
checkbox.CheckBoxSize = 10
checkbox.CalculateOnExit = True
'Set help text
checkbox.Help = "Help text"
paragraph.AppendText("Male" & vbTab)
checkbox = paragraph.AppendCheckBox()
checkbox.Checked = False
checkbox.CheckBoxSize = 10
checkbox.CalculateOnExit = True
paragraph.AppendText("Female")
'Save the Word document
document.Save("Checkbox.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendCheckBox(String, Boolean)
Appends the check box to the paragraph with specified name and default value.
Declaration
WCheckBox AppendCheckBox(string checkBoxName, bool defaultCheckBoxValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | checkBoxName | The string that specifies the name of the check box. |
System.Boolean | defaultCheckBoxValue | A Boolean indicating the default value of the checkbox. True if the checkbox should be checked by default; otherwise, false. |
Returns
Type | Description |
---|---|
WCheckBox | The WCheckBox instance that represents the newly added checkbox. |
Examples
The following example illustrates how to add a checkbox to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
paragraph.AppendText("Gender\t");
//Append new Checkbox
WCheckBox checkbox = paragraph.AppendCheckBox("CheckBox1", true);
//checkbox.Checked = false;
//Set Checkbox size
checkbox.CheckBoxSize = 10;
checkbox.CalculateOnExit = true;
//Set help text
checkbox.Help = "Help text";
paragraph.AppendText("Male\t");
checkbox = paragraph.AppendCheckBox("CheckBox2",false);
//checkbox.Checked = false;
checkbox.CheckBoxSize = 10;
checkbox.CalculateOnExit = true;
paragraph.AppendText("Female");
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As WParagraph = TryCast(section.AddParagraph(), WParagraph)
paragraph.AppendText("Gender" & vbTab)
'Append new Checkbox
Dim checkbox As WCheckBox = paragraph.AppendCheckBox("CheckBox1", True)
'checkbox.Checked = false;
'Set Checkbox size
checkbox.CheckBoxSize = 10
checkbox.CalculateOnExit = True
'Set help text
checkbox.Help = "Help text"
paragraph.AppendText("Male" & vbTab)
checkbox = paragraph.AppendCheckBox("CheckBox2", False)
'checkbox.Checked = false;
checkbox.CheckBoxSize = 10
checkbox.CalculateOnExit = True
paragraph.AppendText("Female")
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendComment(String)
Appends the comment to the paragraph.
Declaration
WComment AppendComment(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The string that specifies the comment. |
Returns
Type | Description |
---|---|
WComment | The WComment instance that represents the newly added comment. |
Examples
The following example illustrates how to add a comment to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Creates a new Word document.
WordDocument document = new WordDocument();
//Add a section and a paragraph in the document
document.EnsureMinimal();
IWParagraph paragraph = document.LastParagraph;
//Append text to the paragraph
paragraph.AppendText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua");
//Add comment to a paragraph
WComment comment = paragraph.AppendComment("comment test");
//Specify the author of the comment
comment.Format.User = "Peter";
//Specify the initial of the author
comment.Format.UserInitials = "St";
//Save and close the Word document
document.Save("Comment.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Creates a new Word document.
Dim document As New WordDocument()
'Add a section and a paragraph in the document
document.EnsureMinimal()
Dim paragraph As IWParagraph = document.LastParagraph
'Append text to the paragraph
paragraph.AppendText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua")
'Add comment to a paragraph
Dim comment As WComment = paragraph.AppendComment("comment test")
'Specify the author of the comment
comment.Format.User = "Peter"
'Specify the initial of the author
comment.Format.UserInitials = "St"
'Save and close the Word document
document.Save("Comment.docx", FormatType.Docx)
document.Close()
End Sub
AppendCrossReference(ReferenceType, ReferenceKind, Entity, Boolean, Boolean, Boolean, String)
Appends a Cross-Reference of specified reference type, reference kind, entity, hyperlink, separators at the end of the paragraph.
Declaration
void AppendCrossReference(ReferenceType referenceType, ReferenceKind referenceKind, Entity referenceEntity, bool insertAsHyperlink, bool includePosition, bool separatorNumber, string separatorString)
Parameters
Type | Name | Description |
---|---|---|
ReferenceType | referenceType | The ReferenceType member that specifies the type of item for which a cross-reference is to be inserted. |
ReferenceKind | referenceKind | The ReferenceKind member that specifies the information to be included in the cross-reference. |
Entity | referenceEntity | The Entity for which a cross-reference is to be inserted. |
System.Boolean | insertAsHyperlink | True if to insert the cross-reference as a hyperlink to the referenced item; otherwise, false. |
System.Boolean | includePosition | True if to insert "above" or "below," depending on the location of the reference item in relation to the cross-reference. |
System.Boolean | separatorNumber | True if to use a separator to separate the numbers from the associated text; otherwise, false.(Used only if the ReferenceKind parameter is set to ParagraphNumberFullContext). |
System.String | separatorString | The string that specifies a separator if the separateNumber parameter is set to true. |
Remarks
Examples
The following example illustrates how to append a cross-reference for bookmark to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
IWParagraph paragraph = section.AddParagraph();
//Add text, bookmark start and end in the paragraph
paragraph.AppendBookmarkStart("Title");
paragraph.AppendText("Northwind Database");
paragraph.AppendBookmarkEnd("Title");
paragraph = section.AddParagraph();
paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases.");
section = document.AddSection();
section.AddParagraph();
paragraph = section.AddParagraph() as WParagraph;
//Get the collection of bookmark start in the word document
List<Entity> items = document.GetCrossReferenceItems(ReferenceType.Bookmark);
paragraph.AppendText("Bookmark Cross Reference starts here ");
//Append the cross reference for bookmark �Title� with ContentText as reference kind
paragraph.AppendCrossReference(ReferenceType.Bookmark, ReferenceKind.ContentText, items[0], true, false, false, string.Empty);
//Update the document Fields
document.UpdateDocumentFields();
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()
Dim section As IWSection = document.AddSection()
Dim paragraph As IWParagraph = section.AddParagraph()
'Add text, bookmark start and end in the paragraph
paragraph.AppendBookmarkStart("Title")
paragraph.AppendText("Northwind Database")
paragraph.AppendBookmarkEnd("Title")
paragraph = section.AddParagraph()
paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases.")
section = document.AddSection()
section.AddParagraph()
paragraph = TryCast(section.AddParagraph(), WParagraph)
'Get the collection of bookmark start in the word document
Dim items As List(Of Entity) = document.GetCrossReferenceItems(ReferenceType.Bookmark)
paragraph.AppendText("Bookmark Cross Reference starts here ")
'Append the cross reference for bookmark �Title� with ContentText as reference kind
paragraph.AppendCrossReference(ReferenceType.Bookmark, ReferenceKind.ContentText, items(0), True, False, False, String.Empty)
'Update the document Fields
document.UpdateDocumentFields()
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AppendDropDownFormField()
Appends the drop down form field to the paragraph.
Declaration
WDropDownFormField AppendDropDownFormField()
Returns
Type | Description |
---|---|
WDropDownFormField | The WDropDownFormField instance that represents the newly added drop down form field. |
AppendDropDownFormField(String)
Appends the drop down form field to the paragraph.
Declaration
WDropDownFormField AppendDropDownFormField(string dropDropDownName)
Parameters
Type | Name | Description |
---|---|---|
System.String | dropDropDownName | The string that specifies the name of the drop drop down field. |
Returns
Type | Description |
---|---|
WDropDownFormField | The WDropDownFormField instance that represents the newly added drop down form field. |
Examples
The following example illustrates how to add a checkbox to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
paragraph.AppendText("Educational Qualification\t");
//Append Dropdown field
WDropDownFormField dropdownfield = paragraph.AppendDropDownFormField("FieldName");
//Add items to the dropdown items collection
dropdownfield.DropDownItems.Add("Higher");
dropdownfield.DropDownItems.Add("Vocational");
dropdownfield.DropDownItems.Add("Universal");
dropdownfield.Enabled = true;
//Set the item index for default value
dropdownfield.DropDownSelectedIndex = 1;
dropdownfield.CalculateOnExit = true;
//Save the Word document
document.Save("Dropdown.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As WParagraph = TryCast(section.AddParagraph(), WParagraph)
paragraph.AppendText("Educational Qualification" & vbTab)
'Append Dropdown field
Dim dropdownfield As WDropDownFormField = paragraph.AppendDropDownFormField("FieldName")
'Add items to the dropdown items collection
dropdownfield.DropDownItems.Add("Higher")
dropdownfield.DropDownItems.Add("Vocational")
dropdownfield.DropDownItems.Add("Universal")
dropdownfield.Enabled = True
'Set the item index for default value
dropdownfield.DropDownSelectedIndex = 1
dropdownfield.CalculateOnExit = True
'Save the Word document
document.Save("Dropdown.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendField(String, FieldType)
Appends field to end of the paragraph with the specified field name and field type.
Declaration
IWField AppendField(string fieldName, FieldType fieldType)
Parameters
Type | Name | Description |
---|---|---|
System.String | fieldName | The string that specifies the field name. |
FieldType | fieldType | The FieldType member that specifies the type of the field. |
Returns
Type | Description |
---|---|
IWField | The IWField instance of the newly added field. |
Examples
The following example illustrates how to append field to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create an instance of WordDocument class (Empty Word Document)
WordDocument document = new WordDocument();
//Add a new section into the Word Document
IWSection section = document.AddSection();
//Add a new paragraph into Word document and append text into paragraph
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Today's Date: ");
//Add the new Date field in Word document with field name and its type.
WField field = paragraph.AppendField("Date", FieldType.FieldDate) as WField;
//Field code used to describe how to display the date
field.FieldCode = @"DATE \@" + "\"MMMM d, yyyy\"";
//Save the document in the given name and format
document.Save("Sample.docx", FormatType.Docx);
//Release the resources occupied by WordDocument instance
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create an instance of WordDocument class (Empty Word Document)
Dim document As New WordDocument()
'Add a new section into the Word Document
Dim section As IWSection = document.AddSection()
'Add a new paragraph into Word document and append text into paragraph
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Today's Date: ")
'Add the new Date field in Word document with field name and its type.
Dim field As WField = TryCast(paragraph.AppendField("Date", FieldType.FieldDate), WField)
'Field code used to describe how to display the date
field.FieldCode = "DATE \@" + """MMMM d, yyyy"""
'Save the document in the given name and format
document.Save("Sample.docx", FormatType.Docx)
'Release the resources occupied by WordDocument instance
document.Close()
End Sub
AppendFootnote(FootnoteType)
Appends footnote or endnotes specified by the type to the paragraph.
Declaration
WFootnote AppendFootnote(FootnoteType type)
Parameters
Type | Name | Description |
---|---|---|
FootnoteType | type | The FootnoteType member that specifies the type of footnote. |
Returns
Type | Description |
---|---|
WFootnote | The WFootnote instance that represents the newly added footnote. |
Remarks
The footnotes and endnotes are differentiated by the type of the footnote.
Examples
The following example illustrates how to add a footnote to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Create a section
IWSection section = document.AddSection();
//Add a paragraph to a section
IWParagraph paragraph = section.AddParagraph();
//Append the text to paragraph
paragraph.AppendText("Working with footnotes");
//Formatting the text
paragraph.ApplyStyle(BuiltinStyle.Heading1);
//Add a paragraph to a section
paragraph = section.AddParagraph();
//Append the footnotes
WFootnote footnote = (WFootnote) paragraph.AppendFootnote(Syncfusion.DocIO.FootnoteType.Footnote);
//Set the footnote character format
footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript;
//Inserts the text into the paragraph
paragraph.AppendText("Sample content for footnotes").CharacterFormat.Bold = true;
//Add footnote text
paragraph = footnote.TextBody.AddParagraph();
paragraph.AppendText("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");
//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()
'Create a section
Dim section As IWSection = document.AddSection()
'Add a paragraph to a section
Dim paragraph As IWParagraph = section.AddParagraph()
'Append the text to paragraph
paragraph.AppendText("Working with footnotes")
'Formatting the text
paragraph.ApplyStyle(BuiltinStyle.Heading1)
'Add a paragraph to a section
paragraph = section.AddParagraph()
'Append the footnotes
Dim footnote As WFootnote = DirectCast(paragraph.AppendFootnote(Syncfusion.DocIO.FootnoteType.Footnote), WFootnote)
'Set the footnote character format
footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript
'Inserts the text into the paragraph
paragraph.AppendText("Sample content for footnotes").CharacterFormat.Bold = True
'Add footnote text
paragraph = footnote.TextBody.AddParagraph()
paragraph.AppendText("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")
�Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
The following example illustrates how to add a endnote to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new document
WordDocument document = new WordDocument();
//Create a section
IWSection section = document.AddSection();
//Add a paragraph to a section
IWParagraph paragraph = section.AddParagraph();
//Append the text to paragraph
paragraph.AppendText("Working with endnotes");
//Formatting the text
paragraph.ApplyStyle(BuiltinStyle.Heading1);
//Add a paragraph to a section
paragraph = section.AddParagraph();
//Append the endnote
WFootnote endnote = (WFootnote) paragraph.AppendFootnote(Syncfusion.DocIO.FootnoteType.Endnote);
//Set the endnote character format
endnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript;
//Insert the text into the paragraph
paragraph.AppendText("Sample content for endnotes").CharacterFormat.Bold = true;
//Add footnote text
paragraph = endnote.TextBody.AddParagraph();
paragraph.AppendText("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");
//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 document
Dim document As New WordDocument()
'Create a section
Dim section As IWSection = document.AddSection()
'Add a paragraph to a section
Dim paragraph As IWParagraph = section.AddParagraph()
'Append the text to paragraph
paragraph.AppendText("Working with endnotes")
'Formatting the text
paragraph.ApplyStyle(BuiltinStyle.Heading1)
'Add a paragraph to a section
paragraph = section.AddParagraph()
'Append the endnote
Dim endnote As WFootnote = DirectCast(paragraph.AppendFootnote(Syncfusion.DocIO.FootnoteType.Endnote), WFootnote)
'Set the endnote character format
endnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript
'Insert the text into the paragraph
paragraph.AppendText("Sample content for endnotes").CharacterFormat.Bold = True
'Add footnote text
paragraph = endnote.TextBody.AddParagraph()
paragraph.AppendText("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")
�Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AppendHTML(String)
Declaration
void AppendHTML(string html)
Parameters
Type | Name | Description |
---|---|---|
System.String | html |
Examples
The following example illustrates how to append html text to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load the template document
WordDocument document = new WordDocument("Template.docx");
//Html string to be inserted
string htmlstring = "This text is inserted as HTML string.
";
IWParagraph paragraph = document.Sections[0].Body.Paragraphs[0];
//Append the Html string to first paragraph in the document
paragraph.AppendHTML(htmlstring);
//Save and close the document
document.Save("Sample.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load the template document
Dim document As New WordDocument("Template.docx")
'Html string to be inserted
Dim htmlstring As String = "This text is inserted as HTML string.
"
Dim paragraph As IWParagraph = document.Sections(0).Body.Paragraphs(0)
'Append the Html string to first paragraph in the document
paragraph.AppendHTML(htmlstring)
'Save and close the document
document.Save("Sample.docx")
document.Close()
End Sub
AppendHyperlink(String, WPicture, HyperlinkType)
Appends the hyperlink to the paragraph with the specified link, picture and type of link.
Declaration
IWField AppendHyperlink(string link, WPicture picture, HyperlinkType type)
Parameters
Type | Name | Description |
---|---|---|
System.String | link | The string that specifies the link. |
WPicture | picture | The WPicture to display. |
HyperlinkType | type | The HyperlinkType member that specifies the link type. |
Returns
Type | Description |
---|---|
IWField | The IWField instance that represents the newly added hyperlink. |
Examples
The following example illustrates how to append field to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Image Hyperlink");
paragraph = section.AddParagraph();
//Create a new image instance and load image
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
//Append new image hyperlink to the paragraph
paragraph.AppendHyperlink("http://www.syncfusion.com", picture, HyperlinkType.WebLink);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Image Hyperlink")
paragraph = section.AddParagraph()
'Create a new image instance and load image
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
'Append new image hyperlink to the paragraph
paragraph.AppendHyperlink("http://www.syncfusion.com", picture, HyperlinkType.WebLink)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendHyperlink(String, String, HyperlinkType)
Appends the hyperlink to the paragraph with the specified link, display text and type of link.
Declaration
IWField AppendHyperlink(string link, string text, HyperlinkType type)
Parameters
Type | Name | Description |
---|---|---|
System.String | link | The string that specifies the link. |
System.String | text | The string that specifies the text to display. |
HyperlinkType | type | The HyperlinkType member that specifies the link type. |
Returns
Type | Description |
---|---|
IWField | The IWField instance that represents the newly added hyperlink. |
Examples
The following example illustrates how to append field to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Web Hyperlink: ");
paragraph = section.AddParagraph();
//Append web hyperlink to the paragraph
IWField field = paragraph.AppendHyperlink("http://www.syncfusion.com", "Syncfusion", HyperlinkType.WebLink);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Web Hyperlink: ")
paragraph = section.AddParagraph()
'Append web hyperlink to the paragraph
Dim field As IWField = paragraph.AppendHyperlink("http://www.syncfusion.com", "Syncfusion", HyperlinkType.WebLink)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendInlineContentControl(ContentControlType)
Declaration
IInlineContentControl AppendInlineContentControl(ContentControlType controlType)
Parameters
Type | Name | Description |
---|---|---|
ContentControlType | controlType |
Returns
Type |
---|
IInlineContentControl |
Examples
The following example illustrates how to append inline content control to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Add new inline control to the paragraph
IInlineContentControl inlineControl = paragraph.AppendInlineContentControl(ContentControlType.RichText);
WTextRange controlText = new WTextRange(document);
controlText.CharacterFormat.Bold = true;
controlText.CharacterFormat.TextColor = Color.Green;
controlText.Text = "Inline content control inserted.";
//Add text range to the control added
inlineControl.ParagraphItems.Add(controlText);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Add new inline control to the paragraph
Dim inlineControl As IInlineContentControl = paragraph.AppendInlineContentControl(ContentControlType.RichText)
Dim textRange As New WTextRange(document)
textRange.CharacterFormat.Bold = True
textRange.CharacterFormat.TextColor = Color.Green
textRange.Text = "Inline content control inserted."
'Add text range to the control added
inlineControl.ParagraphItems.Add(textRange)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendMath()
Appends the mathematical equation to the paragraph.
Declaration
WMath AppendMath()
Returns
Type | Description |
---|---|
WMath | The WMath instance that represents the newly added mathematical equation. |
AppendMath(String)
Appends a mathematical equation to the paragraph using LaTeX syntax.
Declaration
WMath AppendMath(string laTeX)
Parameters
Type | Name | Description |
---|---|---|
System.String | laTeX | The LaTeX syntax representing the mathematical equation. |
Returns
Type | Description |
---|---|
WMath | The WMath instance that represents the newly added mathematical equation. |
Examples
The following example illustrates how to append math using LaTeX to the paragraph.
//Create a new Word document
using(WordDocument wordDocument = new WordDocument())
{
//Adds one section and one paragraph to the document
wordDocument.EnsureMinimal();
//Appends a new mathematical equation to the paragraph using LaTeX syntax.
wordDocument.LastParagraph.AppendMath(@"\dot{a}");
//Saves the Word document
wordDocument.Save("Result.docx", FormatType.Docx);
}
'Create a new Word document
Dim wordDocument As New WordDocument()
'Adds one section and one paragraph to the document
wordDocument.EnsureMinimal()
'Appends a new mathematical equation to the paragraph using LaTeX syntax.
wordDocument.LastParagraph.AppendMath("\dot{a}")
'Saves the Word document
wordDocument.Save("Result.docx", FormatType.Docx)
'Close the document
wordDocument.Close()
AppendOleObject(Byte[], WPicture, OleLinkType)
Appends the OLE object to the paragraph with the specified byte array of the file, picture and link type.
Declaration
WOleObject AppendOleObject(byte[] oleBytes, WPicture olePicture, OleLinkType oleLinkType)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | oleBytes | The byte array of the file. |
WPicture | olePicture | The WPicture instance for the OLE picture. |
OleLinkType | oleLinkType | The OleLinkType member that specifies the link type of OLE object. |
Returns
Type | Description |
---|---|
WOleObject | The WOleObject instance that represents the newly created OLE object. |
Remarks
The OLE object type must be explicitly specified when appending OLE objects using this method.
Examples
The following example illustrates how to append OLE object to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add section to the document
IWSection sec = document.AddSection();
//Add paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Load the picture instance with the image need to be displayed
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
//Get the file as byte array
byte[] olebytes = File.ReadAllBytes("Excel_Template.xlsx");
WOleObject ole = paragraph.AppendOleObject(olebytes, picture, OleLinkType.Embed);
ole.ObjectType = "Excel Worksheet";
//Save the Word document
document.Save("Sample.docx", FormatType.Word2010);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add section to the document
Dim sec As IWSection = document.AddSection()
'Add paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Load the picture instance with the image need to be displayed
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
'Get the file as byte array
Dim olebytes As Byte() = File.ReadAllBytes("Excel_Template.xlsx")
Dim ole As WOleObject = paragraph.AppendOleObject(olebytes, picture, OleLinkType.Embed)
ole.ObjectType = "Excel Worksheet"
'Save the Word document
document.Save("Sample.docx", FormatType.Word2010)
'Close the document
document.Close()
End Sub
AppendOleObject(Byte[], WPicture, OleObjectType)
Appends the OLE object to the paragraph with the specified byte array, picture and object type.
Declaration
WOleObject AppendOleObject(byte[] oleBytes, WPicture olePicture, OleObjectType type)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | oleBytes | The byte array of the file. |
WPicture | olePicture | The WPicture instance for the OLE picture. |
OleObjectType | type | The OleObjectType member that specifies the type of OLE object. |
Returns
Type | Description |
---|---|
WOleObject | The WOleObject instance that represents the newly created OLE object. |
Examples
The following example illustrates how to append OLE object to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add section to the document
IWSection sec = document.AddSection();
//Add paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Load the picture instance with the image need to be displayed
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
//Get the file as byte array
byte[] olebytes = File.ReadAllBytes("Excel_Template.xlsx");
paragraph = sec.AddParagraph();
//Append OLE object
paragraph.AppendOleObject(olebytes, picture, OleObjectType.ExcelWorksheet);
//Save the Word document
document.Save("Sample.docx", FormatType.Word2010);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add section to the document
Dim sec As IWSection = document.AddSection()
'Add paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Load the picture instance with the image need to be displayed
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
'Get the file as byte array
Dim olebytes As Byte() = File.ReadAllBytes("Excel_Template.xlsx")
paragraph = sec.AddParagraph()
'Append OLE object
paragraph.AppendOleObject(olebytes, picture, OleObjectType.ExcelWorksheet)
'Save the Word document
document.Save("Sample.docx", FormatType.Word2010)
'Close the document
document.Close()
End Sub
AppendOleObject(Byte[], WPicture, String)
Appends the OLE object to the paragraph with the specified byte array of the file, picture and file extension.
Declaration
WOleObject AppendOleObject(byte[] oleBytes, WPicture olePicture, string fileExtension)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | oleBytes | The byte array of the file. |
WPicture | olePicture | The WPicture instance for the OLE picture. |
System.String | fileExtension | The string that specifies the file extension. |
Returns
Type | Description |
---|---|
WOleObject | The WOleObject instance that represents the newly created OLE object. |
Examples
The following example illustrates how to append OLE object to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add section to the document
IWSection sec = document.AddSection();
//Add paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Load the picture instance with the image need to be displayed
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
//Get the file as byte array
byte[] olebytes = File.ReadAllBytes("Excel_Template.xlsx");
paragraph = sec.AddParagraph();
//Append OLE object
paragraph.AppendOleObject(olebytes, picture, ".xlsx");
//Save the Word document
document.Save("Sample.docx", FormatType.Word2010);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add section to the document
Dim sec As IWSection = document.AddSection()
'Add paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Load the picture instance with the image need to be displayed
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
'Get the file as byte array
Dim olebytes As Byte() = File.ReadAllBytes("Excel_Template.xlsx")
paragraph = sec.AddParagraph()
'Append OLE object
paragraph.AppendOleObject(olebytes, picture, ".xlsx")
'Save the Word document
document.Save("Sample.docx", FormatType.Word2010)
'Close the document
document.Close()
End Sub
AppendOleObject(Stream, WPicture, OleLinkType)
Appends the OLE object to the paragraph with the specified stream, picture and file link type.
Declaration
WOleObject AppendOleObject(Stream oleStream, WPicture olePicture, OleLinkType oleLinkType)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | oleStream | The System.IO.Stream represents the file stream. |
WPicture | olePicture | The WPicture instance for the OLE picture. |
OleLinkType | oleLinkType | The OleLinkType member that specifies the link type of OLE object. |
Returns
Type | Description |
---|---|
WOleObject | The WOleObject instance that represents the newly created OLE object. |
Remarks
The OLE object type must be explicitly specified when appending OLE objects using this method.
Examples
The following example illustrates how to append OLE object to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add section to the document
IWSection sec = document.AddSection();
//Add paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Load the picture instance with the image need to be displayed
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
FileStream stream = new FileStream("Excel_Template.xlsx", FileMode.Open);
WOleObject ole = paragraph.AppendOleObject(stream, picture, OleLinkType.Embed);
ole.ObjectType = "Excel Worksheet";
//Save the Word document
document.Save("Sample.docx", FormatType.Word2010);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add section to the document
Dim sec As IWSection = document.AddSection()
'Add paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Load the picture instance with the image need to be displayed
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
Dim stream As New FileStream("Excel_Template.xlsx", FileMode.Open)
Dim ole As WOleObject = paragraph.AppendOleObject(stream, picture, OleLinkType.Embed)
ole.ObjectType = "Excel Worksheet"
'Save the Word document
document.Save("Sample.docx", FormatType.Word2010)
'Close the document
document.Close()
End Sub
AppendOleObject(Stream, WPicture, OleObjectType)
Appends the OLE object to the paragraph with the specified stream, picture and object type.
Declaration
WOleObject AppendOleObject(Stream oleStream, WPicture olePicture, OleObjectType type)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | oleStream | The System.IO.Stream represents the file stream. |
WPicture | olePicture | The WPicture instance for the OLE picture. |
OleObjectType | type | The OleObjectType member that specifies the type of OLE object. |
Returns
Type | Description |
---|---|
WOleObject | The WOleObject instance that represents the newly created OLE object. |
Examples
The following example illustrates how to append OLE object to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Open the file to be embedded
FileStream stream = new FileStream("Book1.xlsx", FileMode.Open);
//Load the picture instance with the image need to be displayed
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
//Append the Ole object to the paragraph
WOleObject ole = paragraph.AppendOleObject(stream, picture, OleObjectType.ExcelWorksheet);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Open the file to be embedded
Dim stream As New FileStream("Book1.xlsx", FileMode.Open)
'Load the picture instance with the image need to be displayed
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
'Append the Ole object to the paragraph
Dim ole As WOleObject = paragraph.AppendOleObject(stream, picture, OleObjectType.ExcelWorksheet)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendOleObject(Stream, WPicture, String)
Appends the OLE object to the paragraph with the specified file stream, picture and file extension.
Declaration
WOleObject AppendOleObject(Stream oleStream, WPicture olePicture, string fileExtension)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | oleStream | The System.IO.Stream represents the file stream. |
WPicture | olePicture | The WPicture instance for the OLE picture. |
System.String | fileExtension | The string that specifies the file extension. |
Returns
Type | Description |
---|---|
WOleObject | The WOleObject instance that represents the newly created OLE object. |
Examples
The following example illustrates how to append OLE object to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Open the file to be embedded
FileStream stream = new FileStream("Excel_Template.xlsx", FileMode.Open);
//Load the picture instance with the image need to be displayed
WPicture picture = new WPicture(document);
picture.LoadImage(Image.FromFile("Image.png"));
//Append the Ole object to the paragraph
WOleObject ole = paragraph.AppendOleObject(stream, picture, "xlsx");
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Open the file to be embedded
Dim stream As New FileStream("Excel_Template.xlsx", FileMode.Open)
'Load the picture instance with the image need to be displayed
Dim picture As New WPicture(document)
picture.LoadImage(Image.FromFile("Image.png"))
'Append the Ole object to the paragraph
Dim ole As WOleObject = paragraph.AppendOleObject(stream, picture, "xlsx")
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendPicture(Byte[])
Appends the image specified by the System.Byte array to the end of paragraph.
Declaration
IWPicture AppendPicture(byte[] imageBytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | imageBytes | The System.Byte array of the image to be added. |
Returns
Type | Description |
---|---|
IWPicture | The IWPicture instance that represents the newly added image. |
Examples
The following example illustrates how to append image to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph firstParagraph = section.AddParagraph();
//Get the image and convert to byte array.
Image image = Image.FromFile("Image.png");
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageBytes = stream.ToArray();
//Add image to the paragraph
IWPicture picture = firstParagraph.AppendPicture(imageBytes);
//Set height and width for the image
picture.Height = 100;
picture.Width = 100;
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim firstParagraph As IWParagraph = section.AddParagraph()
'Get the image and convert to byte array.
Dim image__1 As Image = Image.FromFile("Image.png")
Dim stream As New MemoryStream()
image__1.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
Dim imageBytes As Byte() = stream.ToArray()
'Add image to the paragraph
Dim picture As IWPicture = firstParagraph.AppendPicture(imageBytes)
'Set height and width for the image
picture.Height = 100
picture.Width = 100
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendPicture(Byte[], Byte[])
Declaration
IWPicture AppendPicture(byte[] svgData, byte[] imageBytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | svgData | |
System.Byte[] | imageBytes |
Returns
Type |
---|
IWPicture |
Examples
The following example illustrates how to append image to the paragraph.
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph firstParagraph = section.AddParagraph();
//Get the image as byte array.
byte[] imageBytes = File.ReadAllBytes("Image.png");
//Get the SVG image as byte array.
byte[] svgData = File.ReadAllBytes("Image.svg");
//Add SVG image to the paragraph
IWPicture picture = firstParagraph.AppendPicture(svgData, imageBytes);
//Set height and width for the image
picture.Height = 100;
picture.Width = 100;
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim firstParagraph As IWParagraph = section.AddParagraph()
'Get the png image as byte array.
Dim imageBytes As Byte() = File.ReadAllBytes("Image.png")
'Get the SVG image as byte array.
Dim svgData As Byte() = File.ReadAllBytes("Image.svg")
'Add SVG image to the paragraph
Dim picture As IWPicture = firstParagraph.AppendPicture(svgData, imageBytes);
'Set height and width for the image
picture.Height = 100
picture.Width = 100
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
AppendPicture(Stream)
Appends the specified image to the end of paragraph.
Declaration
IWPicture AppendPicture(Stream imageStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | imageStream | The stream that represents the image. |
Returns
Type | Description |
---|---|
IWPicture | The IWPicture instance that represents the newly added image. |
Examples
The following example illustrates how to append image to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Get the image and convert to stream.
Stream stream;
Image image = Image.FromFile("Image.png");
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
//Add image to the paragraph
IWPicture picture = firstParagraph.AppendPicture(stream);
//Set height and width for the image
picture.Height = 100;
picture.Width = 100;
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Get the image and convert to stream.
Dim stream As Stream
Dim image__1 As Image = Image.FromFile("Image.png")
image__1.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
'Add image to the paragraph
Dim picture As IWPicture = firstParagraph.AppendPicture(stream)
'Set height and width for the image
picture.Height = 100
picture.Width = 100
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendShape(AutoShapeType, Single, Single)
Appends Shape of specified type, width and height to the end of paragraph.
Declaration
Shape AppendShape(AutoShapeType autoShapeType, float width, float height)
Parameters
Type | Name | Description |
---|---|---|
AutoShapeType | autoShapeType | The AutoShapeType member that specifies the shape type. |
System.Single | width | The float that specifies the width of the shape. |
System.Single | height | The float that specifies the height of the shape. |
Returns
Type | Description |
---|---|
Shape | The Shape instance that represents the newly added shape. |
Examples
The following example illustrates how to add a shape to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
//Add new shape to the document
Shape rectangle = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100);
//Set position for shape
rectangle.VerticalPosition = 72;
rectangle.HorizontalPosition = 72;
paragraph = section.AddParagraph() as WParagraph;
//Add text body contents to the shape
paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
IWTextRange text = paragraph.AppendText("This text is in rounded rectangle shape");
text.CharacterFormat.TextColor = Color.Green;
text.CharacterFormat.Bold = true;
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As WParagraph = TryCast(section.AddParagraph(), WParagraph)
'Add new shape to the document
Dim rectangle As Shape = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100)
'Set position for shape
rectangle.VerticalPosition = 72
rectangle.HorizontalPosition = 72
paragraph = TryCast(section.AddParagraph(), WParagraph)
'Add text body contents to the shape
paragraph = TryCast(rectangle.TextBody.AddParagraph(), WParagraph)
Dim text As IWTextRange = paragraph.AppendText("This text is in rounded rectangle shape")
text.CharacterFormat.TextColor = Color.Green
text.CharacterFormat.Bold = True
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendSymbol(Byte)
Appends special symbol specified by the character code to end of the paragraph.
Declaration
WSymbol AppendSymbol(byte characterCode)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | characterCode | The byte represents the character code of the symbol. |
Returns
Type | Description |
---|---|
WSymbol | The WSymbol instance that represents the newly added symbol. |
Examples
The following example illustrates how to add a symbol to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("Example of adding symbols to the paragraph: ");
//Insert symbol with character code 100
paragraph.AppendSymbol(100);
//Save and close the Word 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()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("Example of adding symbols to the paragraph: ")
'Insert symbol with character code 100
paragraph.AppendSymbol(100)
'Save and close the Word document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AppendText(String)
Appends the specified text to the end of the paragraph.
Declaration
IWTextRange AppendText(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The string that specifies the text to be appended. |
Returns
Type | Description |
---|---|
IWTextRange | The IWTextRange instance that represents the newly added text. |
Examples
The following example illustrates how to append text to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Add new text to the paragraph
IWTextRange text = paragraph.AppendText("A new text is added to the paragraph.");
text.CharacterFormat.FontSize = 14;
text.CharacterFormat.Bold = true;
text.CharacterFormat.TextColor = Color.Green;
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Add new text to the paragraph
Dim text As IWTextRange = paragraph.AppendText("A new text is added to the paragraph.")
text.CharacterFormat.FontSize = 14
text.CharacterFormat.Bold = True
text.CharacterFormat.TextColor = Color.Green
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendTextBox(Single, Single)
Append textbox to the end of the paragraph with the specified width and height.
Declaration
IWTextBox AppendTextBox(float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.Single | width | The float specifies the width of the textbox. |
System.Single | height | The float specifies the height of the textbox. |
Returns
Type | Description |
---|---|
IWTextBox | The IWTextBox instance that represents the newly added textbox. |
Examples
The following example illustrates how to add a endnote to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Append new textbox to the paragraph
IWTextBox textbox = paragraph.AppendTextBox(150, 75);
//Add new text to the textbox body
IWParagraph textboxParagraph = textbox.TextBoxBody.AddParagraph();
textboxParagraph.AppendText("Text inside text box");
//Save and close the Word 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()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Append new textbox to the paragraph
Dim textbox As IWTextBox = paragraph.AppendTextBox(150, 75)
'Add new text to the textbox body
Dim textboxParagraph As IWParagraph = textbox.TextBoxBody.AddParagraph()
textboxParagraph.AppendText("Text inside text box")
'Save and close the Word document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AppendTextFormField(String)
Appends the text form field to the paragraph with the specified default text.
Declaration
WTextFormField AppendTextFormField(string defaultText)
Parameters
Type | Name | Description |
---|---|---|
System.String | defaultText | The string specifying the default text. To insert default Word text, "null" can be passed as parameter. |
Returns
Type | Description |
---|---|
WTextFormField | The WTextFormField instance that represents the newly added text form field. |
Examples
The following example illustrates how to add a text form field to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
paragraph.AppendText("General Information");
section.AddParagraph();
paragraph = section.AddParagraph() as WParagraph;
IWTextRange text = paragraph.AppendText("Name\t");
text.CharacterFormat.Bold = true;
//Append Text form field
WTextFormField textfield = paragraph.AppendTextFormField(null);
//Set type of Text form field
textfield.Type = TextFormFieldType.RegularText;
textfield.CharacterFormat.FontName = "Calibri";
textfield.CalculateOnExit = true;
//Save the Word document
document.Save("Textfield.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As WParagraph = TryCast(section.AddParagraph(), WParagraph)
paragraph.AppendText("General Information")
section.AddParagraph()
paragraph = TryCast(section.AddParagraph(), WParagraph)
Dim text As IWTextRange = paragraph.AppendText("Name" & vbTab)
text.CharacterFormat.Bold = True
'Append Text form field
Dim textfield As WTextFormField = paragraph.AppendTextFormField(Nothing)
'Set type of Text form field
textfield.Type = TextFormFieldType.RegularText
textfield.CharacterFormat.FontName = "Calibri"
textfield.CalculateOnExit = True
'Save the Word document
document.Save("Textfield.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendTextFormField(String, String)
Appends the text form field to the paragraph with the specified field name and default text.
Declaration
WTextFormField AppendTextFormField(string formFieldName, string defaultText)
Parameters
Type | Name | Description |
---|---|---|
System.String | formFieldName | The string that specifies the name of the form field. |
System.String | defaultText | The string specifying the default text. To insert default Word text, "null" can be passed as parameter. |
Returns
Type | Description |
---|---|
WTextFormField | The WTextFormField instance that represents the newly added text form field. |
Examples
The following example illustrates how to add a text form field to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
WParagraph paragraph = section.AddParagraph() as WParagraph;
paragraph.AppendText("General Information");
section.AddParagraph();
paragraph = section.AddParagraph() as WParagraph;
IWTextRange text = paragraph.AppendText("Date of Birth\t");
text.CharacterFormat.Bold = true;
//Append Text form field
WTextFormField textfield = paragraph.AppendTextFormField("Date field", DateTime.Now.ToString("MM/DD/YY"));
textfield.StringFormat = "MM/DD/YY";
//Set Text form field type
textfield.Type = TextFormFieldType.DateText;
textfield.CalculateOnExit = true;
//Save the Word document
document.Save("Textfield.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As WParagraph = TryCast(section.AddParagraph(), WParagraph)
paragraph.AppendText("General Information")
section.AddParagraph()
paragraph = TryCast(section.AddParagraph(), WParagraph)
Dim text As IWTextRange = paragraph.AppendText("Date of Birth" & vbTab)
text.CharacterFormat.Bold = True
'Append Text form field
Dim textfield As WTextFormField = paragraph.AppendTextFormField("Date field", DateTime.Now.ToString("MM/DD/YY"))
textfield.StringFormat = "MM/DD/YY"
'Set Text form field type
textfield.Type = TextFormFieldType.DateText
textfield.CalculateOnExit = True
'Save the Word document
document.Save("Textfield.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
AppendTOC(Int32, Int32)
Appends the table of content to the end of the paragraph with the specified lower and upper heading levels.
Declaration
TableOfContent AppendTOC(int lowerHeadingLevel, int upperHeadingLevel)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | lowerHeadingLevel | The integer specifying the starting heading level of the table of content. |
System.Int32 | upperHeadingLevel | The integer specifying the ending heading level of the table of content. |
Returns
Type | Description |
---|---|
TableOfContent | The TableOfContent instance that represents the newly added table of content. |
Examples
The following example illustrates how to add a table of contents to the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add the section into the Word document
IWSection section = document.AddSection();
string paraText = "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";
//Add the paragraph into the created section
IWParagraph paragraph = section.AddParagraph();
//Append the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries
paragraph.AppendTOC(1, 3);
//Add the section into the Word document
section = document.AddSection();
//Add the paragraph into the created section
paragraph = section.AddParagraph();
//Add the text for the headings
paragraph.AppendText("First Chapter");
//Set a build in heading style.
paragraph.ApplyStyle(BuiltinStyle.Heading1);
//Add the text into the paragraph
section.AddParagraph().AppendText(paraText);
//Add the section into the Word document
section = document.AddSection();
//Add the paragraph into the created section
paragraph = section.AddParagraph();
//Add the text for the headings
paragraph.AppendText("Second Chapter");
//Set a build in heading style.
paragraph.ApplyStyle(BuiltinStyle.Heading2);
//Add the text into the paragraph
section.AddParagraph().AppendText(paraText);
//Add the section into the Word document
section = document.AddSection();
//Add the paragraph into the created section
paragraph = section.AddParagraph();
//Add the text into the headings
paragraph.AppendText("Third Chapter");
//Set a build in heading style
paragraph.ApplyStyle(BuiltinStyle.Heading3);
//Add the text into the paragraph.
section.AddParagraph().AppendText(paraText);
//Update the table of contents
document.UpdateTableOfContents();
//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 the Word document
Dim section As IWSection = document.AddSection()
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"
'Add the paragraph into the created section
Dim paragraph As IWParagraph = section.AddParagraph()
'Append the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries
paragraph.AppendTOC(1, 3)
'Add the section into the Word document
section = document.AddSection()
'Add the paragraph into the created section
paragraph = section.AddParagraph()
'Add the text for the headings
paragraph.AppendText("First Chapter")
'Set a build in heading style
paragraph.ApplyStyle(BuiltinStyle.Heading1)
'Add the text into the paragraph.
section.AddParagraph().AppendText(paraText)
'Add the section into the Word document
section = document.AddSection()
'Add the paragraph into the created section
paragraph = section.AddParagraph()
'Add the text for the headings
paragraph.AppendText("Second Chapter")
'Set a build in heading style
paragraph.ApplyStyle(BuiltinStyle.Heading2)
'Add the text into the paragraph
section.AddParagraph().AppendText(paraText)
'Add the section into the Word document
section = document.AddSection()
'Add the paragraph into the created section
paragraph = section.AddParagraph()
'Add the text into the headings
paragraph.AppendText("Third Chapter")
'Set a build in heading style
paragraph.ApplyStyle(BuiltinStyle.Heading3)
'Add the text into the paragraph
section.AddParagraph().AppendText(paraText)
'Update the table of contents
document.UpdateTableOfContents()
�Save and close the Word document instance
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyle(BuiltinStyle)
Applies the specified built-in style to the paragraph.
Declaration
void ApplyStyle(BuiltinStyle builtinStyle)
Parameters
Type | Name | Description |
---|---|---|
BuiltinStyle | builtinStyle | The BuiltinStyle member that specifies the style. |
ApplyStyle(String)
Applies the style with the specified name to the paragraph.
Declaration
void ApplyStyle(string styleName)
Parameters
Type | Name | Description |
---|---|---|
System.String | styleName | The string that represents the style name. |
Remarks
The specified style must exists in Styles collection.
Find(String, Boolean, Boolean)
Returns first entry of given string in the paragraph, taking into consideration case sensitive and whole word options.
Declaration
TextSelection Find(string given, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | The string that specifies the text to find. |
System.Boolean | caseSensitive | Set to true to match the case of the text similar to specified in the |
System.Boolean | wholeWord | Set to true to match the whole word of the text similar to specified in the |
Returns
Type | Description |
---|---|
TextSelection | The TextSelection that contains the found text in the paragraph. |
Examples
The following code example demonstrates how to find a particular text in the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document into DocIO instance
WordDocument document = new WordDocument("Template.docx");
WParagraph paragraph = document.Sections[0].Paragraphs[1];
//Find the first occurrence of a particular text in the paragraph
TextSelection textSelection = paragraph.Find("panda", true, true);
//Get the found text as single text range
WTextRange textRange = textSelection.GetAsOneRange();
//Modify the text
textRange.Text = "Replaced text";
//Set highlight color
textRange.CharacterFormat.HighlightColor = Color.Yellow;
//Save and Close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document into DocIO instance
Dim document As New WordDocument("Template.docx")
Dim paragraph As WParagraph = document.Sections(0).Paragraphs(1)
'Find the first occurrence of a particular text in the paragraph
Dim textSelection As TextSelection = paragraph.Find("panda", true, true)
'Get the found text as single text range
Dim textRange As WTextRange = textSelection.GetAsOneRange()
'Modify the text
textRange.Text = "Replaced text"
'Set highlight color
textRange.CharacterFormat.HighlightColor = Color.Yellow
'Save and Close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
See Also
GetStyle()
Returns the IWParagraphStyle applied to the paragraph.
Declaration
IWParagraphStyle GetStyle()
Returns
Type | Description |
---|---|
IWParagraphStyle | The IWParagraphStyle of the current paragraph. |
InsertSectionBreak()
Inserts a section break. Creates new section with the break type new page.
Declaration
WSection InsertSectionBreak()
Returns
Type | Description |
---|---|
WSection | A reference to the newly created section. |
Examples
The following code example illustrates how to insert a section break.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
document.EnsureMinimal();
//Add text to the first section
document.LastParagraph.AppendText("First section");
//Insert section break
WSection newsection = document.LastParagraph.InsertSectionBreak();
//Add new paragraph to the second section
IWParagraph paragraph = newsection.AddParagraph();
paragraph.AppendText("Second 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()
document.EnsureMinimal()
'Add text to the first section
document.LastParagraph.AppendText("First section")
'Insert section break
Dim newsection As WSection = document.LastParagraph.InsertSectionBreak()
'Add new paragraph to the second section
Dim paragraph As IWParagraph = newsection.AddParagraph()
paragraph.AppendText("Second section")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
InsertSectionBreak(SectionBreakCode)
Inserts the section break. Creates new section with the specified break type.
Declaration
WSection InsertSectionBreak(SectionBreakCode breakType)
Parameters
Type | Name | Description |
---|---|---|
SectionBreakCode | breakType | The SectionBreakCode member that specifies the break type. |
Returns
Type | Description |
---|---|
WSection | A reference to the newly created section. |
Examples
The following code example illustrates how to insert a section break.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
document.EnsureMinimal();
//Add text to the first section
document.LastParagraph.AppendText("First section");
//Insert section break
WSection newsection = document.LastParagraph.InsertSectionBreak(SectionBreakCode.Oddpage);
//Add new paragraph to the second section
IWParagraph paragraph = newsection.AddParagraph();
paragraph.AppendText("Second 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()
document.EnsureMinimal()
'Add text to the first section
document.LastParagraph.AppendText("First section")
'Insert section break
Dim newsection As WSection = document.LastParagraph.InsertSectionBreak(SectionBreakCode.Oddpage)
'Add new paragraph to the second section
Dim paragraph As IWParagraph = newsection.AddParagraph()
paragraph.AppendText("Second section")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
RemoveAbsPosition()
Removes the absolute position data, if paragraph has absolute position in the document.
Declaration
void RemoveAbsPosition()
Replace(String, TextSelection, Boolean, Boolean)
Replaces all entries of given string in the paragraph with TextSelection, taking into consideration case sensitive and whole word options.
Declaration
int Replace(string given, TextSelection textSelection, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | The string represents the text to be found. |
TextSelection | textSelection | The TextSelection specifies the text to replace. |
System.Boolean | caseSensitive | Set to true to match the case of the text similar to specified in the |
System.Boolean | wholeWord | Set to true to match the whole word of the text similar to specified in the |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Examples
The following code example demonstrates how to replace all the entries of a text in the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document
WordDocument document = new WordDocument("Template.docx");
WParagraph paragraph = document.Sections[0].Paragraphs[1];
//Find the first occurrence of the regular expression
TextSelection selection = paragraph.Find(new Regex("Panda"));
//Replace all occurrence of a particular regular expression with the text selection in the paragraph
paragraph.Replace("Giant panda", selection, true, false);
//Save and Close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document
Dim document As New WordDocument("Template.docx")
Dim paragraph As WParagraph = document.Sections(0).Paragraphs(1)
'Find the first occurrence of the regular expression
Dim selection As TextSelection = paragraph.Find(New Regex("Panda"))
'Replace all occurrence of a particular regular expression with the text selection in the paragraph
paragraph.Replace("Giant panda", selection, True, False)
'Save and Close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Replace(String, TextSelection, Boolean, Boolean, Boolean)
Replaces all entries of given string in the paragraph with TextSelection, taking into consideration case sensitive, whole word and formatting options.
Declaration
int Replace(string given, TextSelection textSelection, bool caseSensitive, bool wholeWord, bool saveFormatting)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | The string represents the text to be found. |
TextSelection | textSelection | The TextSelection specifies the text to replace. |
System.Boolean | caseSensitive | Set to true to match the case of the text similar to specified in the |
System.Boolean | wholeWord | Set to true to match the whole word of the text similar to specified in the |
System.Boolean | saveFormatting | Set to true if to save source formatting; otherwise, false. |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Examples
The following code example demonstrates how to replace all the entries of a text in the paragraph.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document
WordDocument document = new WordDocument("Template.docx");
WParagraph paragraph = document.Sections[0].Paragraphs[1];
//Find the first occurrence of the regular expression
TextSelection selection = paragraph.Find(new Regex("Panda"));
//Replace all occurrence of a particular regular expression with the text selection in the paragraph
paragraph.Replace("Giant panda", selection, true, false, true);
//Save and Close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document
Dim document As New WordDocument("Template.docx")
Dim paragraph As WParagraph = document.Sections(0).Paragraphs(1)
'Find the first occurrence of the regular expression
Dim selection As TextSelection = paragraph.Find(New Regex("Panda"))
'Replace all occurrence of a particular regular expression with the text selection in the paragraph
paragraph.Replace("Giant panda", selection, True, False, False)
'Save and Close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub