Word新版方程式編輯器釋例(一)

Word新版方程式編輯器釋例(一)

一、目的

Word從2007開始,嘗試提供新版方程式編輯器,對使用者而言,也許無法感覺與原先內建的方程式編輯器(MathType)差別。

但對於開發人員而言,莫過於可以開始在程式中,對數學式進行控制。

對於資料交換或工具撰寫都有相當助益。

此範例中,簡單示範把文字串,變成簡單分數。

 

二、程式碼


{
    return;
}
Word.Document wDoc = this.Application.ActiveDocument;//取得目前作用中文件
Word.Selection nowSel = this.Application.Selection;//取得使用者選取的字串
string nowText = nowSel.Range.Text;//文字內容
Word.Range nowRange = nowSel.Range.OMaths.Add(nowSel.Range);//在目前內容插入方程式物件
Word.OMath nowMath = nowRange.OMaths[1];//取得剛插入的方程式物件
nowMath.BuildUp();//方程式站起來
msgStr = nowSel.Range.Text;

 

三、結果

image