Tag: ms word

有没有办法逐行阅读word文档

我试图提取Word文档中的所有单词。 我可以一次性完成所有操作,如下所示…… Word.Application word = new Word.Application(); doc = word.Documents.Open(@”C:\SampleText.doc”); doc.Activate(); foreach (Word.Range docRange in doc.Words) // loads all words in document { IEnumerable sortedSubstrings = Enumerable.Range(0, docRange.Text.Trim().Length) .Select(i => docRange.Text.Substring(i)) .OrderBy(s => s.Length < 3 ? s : s.Remove(2, Math.Min(s.Length – 2, 2))); wordPosition = (int) docRange.get_Information( Microsoft.Office.Interop.Word.WdInformation.wdFirstCharacterColumnNumber); foreach (var substring in sortedSubstrings) { […]

打开并修改Word文档

我想使用“Microsoft.Office.Interop.Word”打开保存在我的服务器中的word文件。 这是我的代码: object missing = System.Reflection.Missing.Value; object readOnly = false; object isVisible = true; object fileName = “http://localhost:52099/modelloBusta/prova.dotx”; Microsoft.Office.Interop.Word.ApplicationClass applicationWord = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document modelloBusta = new Microsoft.Office.Interop.Word.Document(); try { modelloBusta = applicationWord.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref […]

Interop.Word Documents.Open为null

我正在尝试使用Interop.Word.Application打开.docx文件并转换为PDF。 它作为控制台应用程序,但如果我在我的Web应用程序中使用相同的,它不起作用。 我试图查看该文件夹的权限。 我给了’网络服务’完全控制,但我仍然没有设置对象引用word.Documents.Open。 你能告诉我可能是什么问题吗? 我遇到了这个错误。 请告诉我。 我很感激任何建议。 谢谢。 Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); object oMissing = System.Reflection.Missing.Value; word.Visible = false; word.ScreenUpdating = false; string fileName = @”c:\OUTPUT\test.docx”); Document doc = word.Documents.Open(filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref […]

如何使用OpenXml 2.0将任何文件类型嵌入到Microsoft Word中

我花了很多时间试图找出一种使用OpenXml 2.0将任何文件嵌入Microsoft Word的好方法; Office文档相当容易,但其他文件类型如PDF,TXT,GIF,JPG,HTML等等。 在C#中使用任何文件类型的好方法是什么?

从MS-Word ApplicationClass获取PID?

考虑以下代码: using Microsoft.Office.Interop.Word; ApplicationClass _application = new ApplicationClass(); 我可以从_application启动的Winword.exe进程中获取PID吗? 我需要PID因为文件损坏,我只是不能退出ApplicationClass,即使使用这段代码: _application.Quit(ref saveFile, ref missing, ref missing); System.Runtime.InteropServices.Marshal.ReleaseComObject(_application); GC.Collect(); GC.WaitForPendingFinalizers(); 我无法搜索winword.exe进程并将其杀死,因为我会有几个,而且我不知道要杀哪个。 如果我可以为每个ApplicationClass获取一个PID,我可以杀死正确的winword.exe进程,这会给我带来麻烦。

使用Open XML SDK替换Word文件中的书签文本

我假设v2.0更好……他们有一些很好的“如何:……”的例子,但是书签看起来并不像表格那么明显……书签是由两个 XML元素BookmarkStart定义的书签结束 。 我们有一些带有书签的模板作为书签,我们只想用其他文本替换书签……没有奇怪的格式化,但如何选择/替换书签文字?

OpenXML标记搜索

我正在编写一个.NET应用程序,它应该读取200页长的.docx文件(通过DocumentFormat.OpenXML 2.5)来查找文档应该包含的某些标记的所有出现。 为了清楚起见,我不是在寻找OpenXML标签,而是寻找应该由文档编写者设置到文档中的标签,作为我需要在第二阶段填写的值的占位符。 此类标签应采用以下格式: (其中TAG可以是任意字符序列)。 正如我所说,我必须找到所有这些标签的出现加上(如果可能)找到已发现标签出现的“页面”。 我在Web上发现了一些东西,但不止一次基本方法是将文件的所有内容转储到字符串中,然后查看这样的字符串,无论.docx编码如何。 这或者导致误报或根本不匹配(而测试.docx文件包含多个标签),其他示例可能与我对OpenXML的了解有点差异。 找到这样的标签的正则表达式模式应该是这样的: 标签可以在整个文档中找到(在表格,文本,段落内,也可以在页眉和页脚中)。 我在Visual Studio 2013 .NET 4.5中进行编码,但如果需要,我可以回来。 PS我更喜欢不使用Office Interop API的代码,因为目标平台不会运行Office。 我可以生成的最小.docx示例存储此内部文档 TRY <!TAG1 !> TRY2 最诚挚的问候,迈克

如何使用后期绑定访问Microsoft Word现有实例

我正在c#中开发一些代码,我将与Microsoft Word进行交互。 我希望能够选择重新使用现有实例,或者作为创建新实例的替代方法。 请记住,我想使用LATE BINDING完成所有这些…可以肯定地说我已经找到了在创建新实例时如何使事情正常工作..我只是调用Activator.CreateInstance等。 我遇到的问题是如何重用现有实例,例如,Word已经打开,我想使用该实例。 有没有Activator.UseExistingInstance? 或者类似的东西? 谢谢!

如何从Word 2010 Addin(用C#开发)获取“KeyPress”事件?

如何从C#开发的Word 2010 Addin中“捕获”KeyPress事件? 注意:我不是在寻找像钩子那样的“复杂”解决方案,而是从对象模型中寻找漂亮而整洁的.NET。 我“在我手中”的应用程序对象是: Microsoft.Office.Interop.Word.Application 最好的祝福

逐行阅读word文档

我正在尝试使用C#阅读word文档。 我能够获得所有文本但我希望能够逐行读取并存储在列表中并绑定到gridview 。 目前,我的代码只返回一个包含所有文本的项目列表(不是根据需要逐行)。 我正在使用Microsoft.Office.Interop.Word库来读取该文件。 以下是我的代码: Application word = new Application(); Document doc = new Document(); object fileName = path; // Define an object to pass to the API for missing parameters object missing = System.Type.Missing; doc = word.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref […]