在word文档中添加时识别的数学函数显示不正确 [英] Recognized math functions when added in word document does not appear appropriately
问题描述
我使用word interop dll添加数学函数(乳胶脚本)
对于希腊字符我使用相应的utf-16码。其他乳胶脚本受到尊重。例如。 F_abc在F的下标中表示为abc。我面临的问题是,识别的数学函数 - min,max如果在我的脚本中作为下标出现,则
不会被放置在下标中并显示为正常的自由文本。 e'g F_max给出F_max inword文档。
如果我通过打开word文档删除explicityl,从设置 - 文件 - 选项 - 校对 - 自动更正选项 - 数学自动校正 - 识别函数" 。然后只有你得到预期的结果。但是使用代码,没有删除功能的选项。
OMathAutoCorrect.Functions.Item有Add()但没有Delete()
请提供我可以解决这个问题的方法。
请参考以下代码:
var script = @" \ delta D_sin M_max M_min" ;;
script = script.Replace(@" \ delta"," \ u03B4");
var range1 = objPara2.Range;
range1.OMaths.Add(range1);
OMathFunction myFunction = range1.OMaths [1] .Functions.Add(range1,WdOMathFunctionType.wdOMathFunctionBox); OMathBox myBox = myFunction.Box;
myBox.E.Range.Text = script; myBox.E.BuildUp();
您好PS20,
请尝试以下方法代码:
使用System;
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
使用Word = Microsoft.Office.Interop.Word;
使用System.Diagnostics;
名称空间VSTOInsertEquations
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent() ;
}
private void button1_Click(object sender,EventArgs e)
{
Word.Application wdApplication = null;
Process [] pl = Process.GetProcessesByName(" WINWORD.exe");
if(pl.Length> 0)
{
wdApplication =(Word.Application)System.Runtime.InteropServices
.Marshal.GetActiveObject(" Word.Application") ;
}
else
{
wdApplication = new Word.Application();
}
if(wdApplication!= null)
{
Word.Document newDocument = wdApplication.Documents.Add();
//以下代码将添加Nary方程
Word.Range wdFunctionR = wdApplication.Selection.OMaths
.Add(wdApplication.Selection.Range);
Word.OMathFunction wdFunction = wdApplication.Selection
.OMaths [1] .Functions.Add(wdApplication.Selection.Range,
Word.WdOMathFunctionType.wdOMathFunctionNary);
Word.OMathNary wdNary = wdFunction.Nary;
wdNary.Char = 8721;
wdNary.Grow = false;
wdNary.SubSupLim = false;
wdNary.HideSub = false;
wdNary.HideSup = false;
//以下代码将在Nary函数中设置值
Word.Selection wdSelection = wdApplication.Selection;
object unit = Word.WdUnits.wdCharacter;
object lu = Word.WdUnits.wdLine;
对象计数= 1;
object dcount = 2;
object tcount = 3;
wdSelection.MoveLeft(ref unit,ref count);
wdSelection.TypeText(" 11");
wdSelection.MoveLeft(ref unit,ref tcount);
wdSelection.TypeText(" 12");
wdSelection.MoveDown(ref lu,ref count);
wdSelection.TypeText(" 13");
wdNary.Application.Visible = true;
}
}
}
}有关详细信息,请参阅以下内容链接:
希望它可以帮到你。
最好的问候,
I am using word interop dll to add the math functions (latex scripts)
For greek characters I use the corresponding utf-16 code. Other latex scripts are respected. For eg. F_abc is represented as abc in subscript of F. The problem I face is, the recognized math functions - min, max if are present in my script as subscript they dont get placed at subscripts and appear as normal free text. e'g F_max gives F_max inword document.
If I delete explicityl by opening the word document, from the settings - File-Options-Proofing-AutoCorrect Options-Math auto correct-Recognized Functions". Then only you get the result as expected. But with code, there is no option to delete the functions. OMathAutoCorrect.Functions.Item has Add() but no Delete()
Please provide a way in which I could solve this issue.
Please refer below code :
var script = @"\delta D_sin M_max M_min";
script = script.Replace(@"\delta", "\u03B4");
var range1 = objPara2.Range;
range1.OMaths.Add(range1);
OMathFunction myFunction = range1.OMaths[1].Functions.Add( range1, WdOMathFunctionType.wdOMathFunctionBox); OMathBox myBox = myFunction.Box;
myBox.E.Range.Text = script; myBox.E.BuildUp();
Hi PS20,
Please try the following code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Word = Microsoft.Office.Interop.Word; using System.Diagnostics; namespace VSTOInsertEquations { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Word.Application wdApplication = null; Process[] pl = Process.GetProcessesByName("WINWORD.exe"); if (pl.Length > 0) { wdApplication = (Word.Application)System.Runtime.InteropServices .Marshal.GetActiveObject("Word.Application"); } else { wdApplication = new Word.Application(); } if (wdApplication != null) { Word.Document newDocument = wdApplication.Documents.Add(); //Following code will add a Nary Equation Word.Range wdFunctionR = wdApplication.Selection.OMaths .Add(wdApplication.Selection.Range); Word.OMathFunction wdFunction = wdApplication.Selection .OMaths[1].Functions.Add(wdApplication.Selection.Range, Word.WdOMathFunctionType.wdOMathFunctionNary); Word.OMathNary wdNary = wdFunction.Nary; wdNary.Char = 8721; wdNary.Grow = false; wdNary.SubSupLim = false; wdNary.HideSub = false; wdNary.HideSup = false; //Following code will setup value in Nary Function Word.Selection wdSelection = wdApplication.Selection; object unit = Word.WdUnits.wdCharacter; object lu = Word.WdUnits.wdLine; object count = 1; object dcount = 2; object tcount = 3; wdSelection.MoveLeft(ref unit, ref count); wdSelection.TypeText("11"); wdSelection.MoveLeft(ref unit, ref tcount); wdSelection.TypeText("12"); wdSelection.MoveDown(ref lu, ref count); wdSelection.TypeText("13"); wdNary.Application.Visible = true; } } } }For more information, please see the following links:
Insert a mathematical formula in to a word document programmatically
Programmatically adding math equations to Word document from C#
Hopefully it helps you.
Best Regards,
这篇关于在word文档中添加时识别的数学函数显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!