使用VSTO向Word文档中添加数学公式
2012-02-09 12:49
387 查看
这是个极其简单的实例,用来向Word文档中添加一个数学汇总公式。
相关资源:http://download.csdn.net/detail/tx_officedev/4053367
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(); //一下代码添加了汇总公式 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; //以下代码将数值填写入公式 Word.Selection wdSelection = wdApplication.Selection; object unit = Word.WdUnits.wdCharacter; object lu = Word.WdUnits.wdLine; object count = 1; 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; } } } }
相关资源:http://download.csdn.net/detail/tx_officedev/4053367
相关文章推荐
- 使用VSTO向Word文档中添加数学公式
- JAVA不使用POI给Word文档添加水印
- 使用MathJax在博客园里添加数学公式
- 使用点聚 weboffice 以及vsto、 web service 实现word 的自动化文档处理
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 在word文档中添加目录(包括项目符号、编号、多级列表使用方法)
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 使用vba进行Word文档的数学格式设置
- DOxygen for C++使用说明——添加数学公式
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 给word文档添加水印(图片、文字),我修改过了,可直接使用
- 使用VSTO自动生成word文档
- Itext操作word文档动态生成数学试卷及Latex转mathML公式处理方式
- 使用OpenXml SDK 给Word文档添加样式并应用于文本
- 使用word 2010宏为文档自动添加密码
- 使用html方式在博客中添加数学公式
- 如何使用C#向Word文档中添加表格和嵌套表格
- VSTO中向word文档中添加Content Control 、CustomXML
- Android开发——使用Jword生成本地word文档
- 给您的文字编辑程序添加一剂“后悔药”-使用RichTextBox控件提供用户编辑功能,加入类似word的“撤销”和“恢复”功能