Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Create mathematical equation
The following example shows you how to insert simple mathematical equation.
import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.WordDocument; import com.independentsoft.office.word.math.Denominator; import com.independentsoft.office.word.math.Fraction; import com.independentsoft.office.word.math.MathRun; import com.independentsoft.office.word.math.Numerator; import com.independentsoft.office.word.math.OfficeMath; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); MathRun xRun = new MathRun("x"); MathRun yRun = new MathRun("y"); MathRun zRun = new MathRun("z"); Numerator xNumerator = new Numerator(); xNumerator.getMathElements().add(xRun); Denominator yDenominator = new Denominator(); yDenominator.getMathElements().add(yRun); Denominator zDenominator = new Denominator(); zDenominator.getMathElements().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.getMathElements().add(fraction1); math.getMathElements().add(plusRun); math.getMathElements().add(fraction2); math.getMathElements().add(resultRun); Paragraph paragraph = new Paragraph(); paragraph.add(math); doc.getBody().add(paragraph); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*