자바 프로그램 생 성 공식 docx 문서 에서

2852 단어 자바formuladocx
package cn.com.eduedu.jee.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.xwpf.usermodel.*;

import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMath;
import org.openxmlformats.schemas.officeDocument.x2006.math.CTRad;
import org.openxmlformats.schemas.officeDocument.x2006.math.CTR;
import org.openxmlformats.schemas.officeDocument.x2006.math.STStyle;
public class MSDocxCreateFormulaInDocx {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        XWPFDocument doc= new XWPFDocument();

          XWPFParagraph paragraph = doc.createParagraph();
          XWPFRun run=paragraph.createRun();  
          run.setText("The Formula: ");

          CTOMath cTOMath = paragraph.getCTP().addNewOMath();
          CTR cTR = cTOMath.addNewR();
          cTR.addNewRPr().addNewSty().setVal(STStyle.P);
          cTR.addNewT2().setStringValue("a²+b²=c²");

          run=paragraph.createRun();  
          run.setText(" text after the formula");

          paragraph = doc.createParagraph();
          run=paragraph.createRun();  
          run.setText("The Formula: ");

          cTOMath = paragraph.getCTP().addNewOMath();
          CTRad cTRad = cTOMath.addNewRad();
          cTR = cTRad.addNewDeg().addNewR();
          cTR.addNewRPr().addNewSty().setVal(STStyle.P);
          cTR.addNewT2().setStringValue("2");
          cTR = cTRad.addNewE().addNewR();
          cTR.addNewRPr().addNewSty().setVal(STStyle.P);
          cTR.addNewT2().setStringValue("a²+b²");

          run=paragraph.createRun();  
          run.setText(" text after the formula");  

          doc.write(new FileOutputStream("d:\\WordFormula.docx"));
          doc.close();
    }
}

옮 겨 실 었 는데 어디서 돌 았 는 지 못 찾 겠 어 요.죄송합니다.

좋은 웹페이지 즐겨찾기