office-interop

Microsoft Office VSTO addin: How to access ribbon xml controls from ThisAddIn class

梦想与她 提交于 2020-04-29 03:49:28
问题 In my VS2019 VSTO project for WORD AddIn , I have created button in a tab by using Ribbon XML as follows. And VS2019 auto-generated the ThisAddIn.cs class shown below. Question : How can I programmatically access the button control btnButton of Ribbon XML from ThisAddIn.cs class? Remark : There are some officials such as this one that shows how to do it for a Ribbon Designer . But, I need to do it for Ribbon XML . Ribbon1.XML : <ribbon> <tabs> <tab id="TabID" label="TEST"> <group id="MyGroup"

Interop Word & Excel : Can't close an Excel workbook embedded in Word document

时光毁灭记忆、已成空白 提交于 2020-04-12 04:06:34
问题 I got an error when i'm closing the Excel workbook embedded in a Word document. This document got only one Excel chart. Nothing else : texts, etc... This is the code : Application _application = new Application { Visible = false, }; object oFilename = fileName; object oFormat = WdOpenFormat.wdOpenFormatXMLDocument; _document = _application.Documents.Open( ref oFilename, ref _missing, ref _faux, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing, ref oFormat,

Interop Word & Excel : Can't close an Excel workbook embedded in Word document

▼魔方 西西 提交于 2020-04-12 04:06:06
问题 I got an error when i'm closing the Excel workbook embedded in a Word document. This document got only one Excel chart. Nothing else : texts, etc... This is the code : Application _application = new Application { Visible = false, }; object oFilename = fileName; object oFormat = WdOpenFormat.wdOpenFormatXMLDocument; _document = _application.Documents.Open( ref oFilename, ref _missing, ref _faux, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing, ref oFormat,

Microsoft Excel Application entry is missing in DCOM Config

ぃ、小莉子 提交于 2020-04-11 04:34:29
问题 The entry for "Microsoft Excel Application" is not there in DCOM Config (tried in both 32-bit and 64-bit). How can I make it shows up there? I have Microsoft Office installed. 回答1: If you cannot find 'Microsoft Excel Application' in either 32-bit or 64-bit DCOMCNFG, you might go into registry to HKEY_CLASSES_ROOT/AppID and find the CLSID for your version of Excel (Excel 2013 has an AppID of {00020812-0000-0000-C000-000000000046}) Check that the (Default) REG_SZ for this key has a value set

Why ExcelApplication.Workbooks.Count is showing zero even when I have an Excel workbook open

╄→гoц情女王★ 提交于 2020-02-05 08:26:09
问题 ExcelApplication.Workbooks.Count is showing count = 0 even when I have a document open. ExcelApplication.Workbooks.Count shows count = 1 when the document opened is not in protected view. But when the opened document is PROTECTED VIEW the ExcelApplication.Workbooks.Count shows 0. Why the workbook count is 0 in case of protected view excel? 回答1: Because: A workbook displayed in a Protected View window is not a member of the Workbooks collection. If you need to get a handle on a protected

Why ExcelApplication.Workbooks.Count is showing zero even when I have an Excel workbook open

回眸只為那壹抹淺笑 提交于 2020-02-05 08:24:47
问题 ExcelApplication.Workbooks.Count is showing count = 0 even when I have a document open. ExcelApplication.Workbooks.Count shows count = 1 when the document opened is not in protected view. But when the opened document is PROTECTED VIEW the ExcelApplication.Workbooks.Count shows 0. Why the workbook count is 0 in case of protected view excel? 回答1: Because: A workbook displayed in a Protected View window is not a member of the Workbooks collection. If you need to get a handle on a protected

Find a range of text with specific formatting with Word interop

妖精的绣舞 提交于 2020-02-02 12:51:48
问题 I have a MS Word add-in that needs to extract text from a range of text based solely on its formatting: in my case in particular, if the text is underlined or struck through, the range of characters/words that are underlined or struck through need to be found so that I can keep track of them. My first idea was to use Range.Find , as is outlined here, but that won't work when I have no idea what the string is that I'm looking for: var rng = doc.Range(someStartRange, someEndRange); rng.Find

Adding tables in word document in loop

北战南征 提交于 2020-01-30 12:27:05
问题 I want to add multiple tables in word document programmatically. I have tried following code in order to add table (in sample code below I have not used loop though) Microsoft.Office.Interop.Word.Table imageTable1 = wordDoc.Tables.Add(initialRange, 1, 2, ref oMissing, ref oMissing); imageTable1.Rows.SetHeight(40, WdRowHeightRule.wdRowHeightExactly); imageTable1.AllowAutoFit = true; var text = "ABC"; // Add feature name in bold in table if (!string.IsNullOrEmpty(text)) { Cell cell1 =

Could not load file or assembly 'Interop.Microsoft.Office.Core, Version=2.4.0.0, …' when changing from .NET 3.5 to 4.5.1

倖福魔咒の 提交于 2020-01-25 21:21:22
问题 I am upgrading my WinForms application from .NET 3.5 to 4.5.1. The 3.5 application works just fine. After the upgrade to .NET 4.5.1 I started getting the following exception: System.IO.FileNotFoundException: Could not load file or assembly 'Interop.Microsoft.Office.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'Interop.Microsoft.Office.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null'

Programmatically insert image to word with link to file

夙愿已清 提交于 2020-01-25 12:49:48
问题 In Word document, there is an option in the insert image dialog box insert button that is "Link to File", where I can input a image url link into the file name input box. Word will then pull that image from the link. As such everytime the user opens the word document, it will pull that image from the link. How do i do that with Microsoft Interop? Ive tried to use this method http://www.c-sharpcorner.com/uploadfile/hrojasara/insert-picture-with-hyperlink-in-word-file-using-C-Sharp/ However it