Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Create mathematical equation
The following example shows you how to insert simple mathematical equation.
C# example
using System; using Independentsoft.Office.Word; using Independentsoft.Office.Word.Math; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); MathRun xRun = new MathRun("x"); MathRun yRun = new MathRun("y"); MathRun zRun = new MathRun("z"); Numerator xNumerator = new Numerator(); xNumerator.MathElements.Add(xRun); Denominator yDenominator = new Denominator(); yDenominator.MathElements.Add(yRun); Denominator zDenominator = new Denominator(); zDenominator.MathElements.Add(zRun); Fraction fraction1 = new Fraction(xNumerator, yDenominator); Fraction fraction2 = new Fraction(xNumerator, zDenominator); MathRun plusRun = new MathRun("+"); MathRun resultRun = new MathRun("=100"); OfficeMath math = new OfficeMath(); math.MathElements.Add(fraction1); math.MathElements.Add(plusRun); math.MathElements.Add(fraction2); math.MathElements.Add(resultRun); Paragraph paragraph = new Paragraph(); paragraph.Add(math); doc.Body.Add(paragraph); doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports Independentsoft.Office.Word Imports Independentsoft.Office.Word.Math Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument() Dim xRun As MathRun = New MathRun("x") Dim yRun As MathRun = New MathRun("y") Dim zRun As MathRun = New MathRun("z") Dim xNumerator As Numerator = New Numerator xNumerator.MathElements.Add(xRun) Dim yDenominator As Denominator = New Denominator yDenominator.MathElements.Add(yRun) Dim zDenominator As Denominator = New Denominator zDenominator.MathElements.Add(zRun) Dim fraction1 As Fraction = New Fraction(xNumerator, yDenominator) Dim fraction2 As Fraction = New Fraction(xNumerator, zDenominator) Dim plusRun As MathRun = New MathRun("+") Dim resultRun As MathRun = New MathRun("=100") Dim math As OfficeMath = New OfficeMath math.MathElements.Add(fraction1) math.MathElements.Add(plusRun) math.MathElements.Add(fraction2) math.MathElements.Add(resultRun) Dim paragraph As Paragraph = New Paragraph paragraph.Add(math) doc.Body.Add(paragraph) doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*