- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 MathML 创建一些数据 block ,我需要通过 OpenXML SDK 将其插入到 docx 文件中。我听说这是可能的,但我没有做到。有人可以帮我解决这个问题吗?
最佳答案
据我所知,OpenXml SDK 不支持开箱即用的表示 MathML。
相反,OpenXml SDK 支持 Office MathML。因此,要将演示文稿 MathML 插入到 word 文档中,我们首先需要将演示文稿 MathML 转换为 Office MathML。
幸运的是,微软提供了一个 XSL 文件(称为 MML2OMML.xsl)来转换表示 MathML到 Office MathML。文件 MML2OMML.xsl 位于 %ProgramFiles%\Microsoft Office\Office12
下。结合 .Net Framework 类XslCompiledTransform
我们能够将演示文稿 MathML 转换为 Office MathML。
下一步是从转换后的 MathML 创建一个 OfficeMath
对象。OfficeMath
类表示包含 WordprocessingML 的运行,应将其视为 Office Open XML Math 进行处理。更多信息请引用 MSDN .
MathML 演示文稿不包含字体信息。为了得到一个好的结果我们必须将字体信息添加到创建的 OfficeMath
对象中。
在最后一步中,我们必须将 OfficeMath
对象添加到我们的 word 文档中。在下面的示例中,我只是搜索第一个 Paragraph
名为 template.docx 的 word 文档,并将 OfficeMath
对象添加到找到的段落中。
XslCompiledTransform xslTransform = new XslCompiledTransform();
// The MML2OMML.xsl file is located under
// %ProgramFiles%\Microsoft Office\Office12\
xslTransform.Load("MML2OMML.xsl");
// Load the file containing your MathML presentation markup.
using (XmlReader reader = XmlReader.Create(File.Open("mathML.xml", FileMode.Open)))
{
using (MemoryStream ms = new MemoryStream())
{
XmlWriterSettings settings = xslTransform.OutputSettings.Clone();
// Configure xml writer to omit xml declaration.
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.OmitXmlDeclaration = true;
XmlWriter xw = XmlWriter.Create(ms, settings);
// Transform our MathML to OfficeMathML
xslTransform.Transform(reader, xw);
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms, Encoding.UTF8);
string officeML = sr.ReadToEnd();
Console.Out.WriteLine(officeML);
// Create a OfficeMath instance from the
// OfficeMathML xml.
DocumentFormat.OpenXml.Math.OfficeMath om =
new DocumentFormat.OpenXml.Math.OfficeMath(officeML);
// Add the OfficeMath instance to our
// word template.
using (WordprocessingDocument wordDoc =
WordprocessingDocument.Open("template.docx", true))
{
DocumentFormat.OpenXml.Wordprocessing.Paragraph par =
wordDoc.MainDocumentPart.Document.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().FirstOrDefault();
foreach (var currentRun in om.Descendants<DocumentFormat.OpenXml.Math.Run>())
{
// Add font information to every run.
DocumentFormat.OpenXml.Wordprocessing.RunProperties runProperties2 =
new DocumentFormat.OpenXml.Wordprocessing.RunProperties();
RunFonts runFonts2 = new RunFonts() { Ascii = "Cambria Math", HighAnsi = "Cambria Math" };
runProperties2.Append(runFonts2);
currentRun.InsertAt(runProperties2, 0);
}
par.Append(om);
}
}
}
关于OpenXML SDK 和 MathML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10993621/
我有一个 MATHML 公式(由 http://www.mathtoweb.com/cgi-bin/mathtoweb_online.pl 生成)。我想将其粘贴到 Libreoffice 中。我怎样才
我不明白什么? 下面的代码工作正常: from sympy.printing.mathml import print_mathml s = "x**2 + 8*x + 16" print_mathml
我有一些网页大量使用 MathJax(或 MathML?),我想将其转换成电子书并显示在我的 kindle 上,它不支持足够的 javascript,也不支持 MathML。所以我想预处理 .html
我的浏览器 Firefox 3.6 似乎可以很好地显示 W3C 测试套件中的 Mathml 方程。但是,如果我将代码复制到我的网页中,例如 here ,所有 Firefox 生成的都是类似于 x y
我今天发现 Windows 7 带有一个非常令人印象深刻的 MathPanel 实用程序,用于执行方程的手写识别: 这很好。 (这里我已经输入了 sRGB 颜色空间 Gamma 转换部分的公式) 但现
我们很快就会开始开发 TeX 到 MathML 的转换器。所以,我想知道哪些浏览器(从哪个版本开始)正式支持 MathML?谢谢 最佳答案 几乎没有,只有 Firefox 和 Safari 可以处理
我试图显示一个简单的方程式,但它不起作用。我的代码如下(html5): a i =
我有一个包含文本区域的页面。用户将在其中输入 mathML,当用户单击输出按钮时,MathML 应呈现并显示在文本区域下方。但是渲染没有发生。 Textarea 可能包含多个用于渲染的 mathml
我正在尝试构建与 this site 相同的功能用户将在文本区域中输入数学表达式并将其呈现为 MathML 格式。 例子: Input expression string: cos(x^3) Then
快速了解 MathML 及其在世界范围内的使用的最佳方法是什么? 我的意思是: 你用什么来渲染/编辑它 它是否用于您可以向我指出的任何商业/开源应用程序 它是否流行并被大量使用? 是否有可以在 C#、
我在使用我们的学习管理系统 (LMS) 中内置的 MathML 编辑器时发现了一些奇怪的东西。当我输入 float 时,它用 包裹小数点标签。 例如,我期望 1.2输出为: 1.2 但是,编辑器输出
我一直在努力为 ckeditor 添加 mathml 支持。我浏览了几个链接,但似乎没有一个起作用。我什至尝试过 ckeditor 的 WIRIS 插件,但它没有给我任何结果。对于WIRIS,我关注了
我在使用我们的学习管理系统 (LMS) 中内置的 MathML 编辑器时发现了一些奇怪的东西。当我输入 float 时,它用 包裹小数点标签。 例如,我期望 1.2输出为: 1.2 但是,编辑器输出
我使用 MathML 创建一些数据 block ,我需要通过 OpenXML SDK 将其插入到 docx 文件中。我听说这是可能的,但我没有做到。有人可以帮我解决这个问题吗? 最佳答案 据我所知,O
我正在使用 MathDox用于生成 MathML 的公式编辑器。现在我想将 MathDox 生成的 MathML 转换为表达式,稍后我可以使用它来评估以找到答案。 For eg: MathML:
我想像这样转换表达式: “a*x^2+b*x^2+c+d”…… “对数((a*x)/sin(x))”... “1/x”... 使用 JavaScript 进入 MathML。有什么建议么?我找到的最接
我有一个 PHP 脚本输出:((5^2x^2)^2+3)/(sqrt(sqrt(81))) 我希望它像您编写的那样正确格式化。 在哪里可以找到这样的 ASCII 到 MathML 转换器:http:/
我正在尝试为用户实现一种输入简化数学符号的方法,而不是传统的 LaTex 符号。然后将使用 MathJax 呈现表达式的结果。但我似乎找不到“简化的数学符号”或 ad-hoc ASCII 到 late
具体来说(MathJax 不是我要找的)我有一个网页,里面有一些 MathML。“FireFox”浏览器可以很好地解析它,但是当我尝试通过 javascript 添加相同的代码时,它没有'解析它。如何
MathML是一种编写数学的网络标准,可以轻松缩放而无需像素化(就像 SVG)、复制和粘贴以及屏幕阅读器阅读。 Chrome 拒绝在存在 JavaScript polyfill 的基础上实现它。 (I
我是一名优秀的程序员,十分优秀!