office-interop

different format into one single line Interop.word

放肆的年华 提交于 2019-12-17 20:37:54
问题 I've been trying to figure out how to insert 2 different formats into the same paragraph using interop.word in c# like this: hello planet earth here's what I want to do 回答1: Assuming you have your document defined as oDoc, the following code should get you the desired result: Word.Paragraph oPara = oDoc.Content.Paragraphs.Add(ref oMissing); oPara.Range.Text = "hello planet earth here's what I want to do"; object oStart = oPara.Range.Start + 13; object oEnd = oPara.Range.Start + 18; Word.Range

How do you pass the owner window to Show() method overload?

孤者浪人 提交于 2019-12-17 19:24:49
问题 I'm working on an Excel add in that opens a winform after the user clicks a button on a ribbon bar. This button needs to be non-modal so that the user can still interact with the parent window, but it also must remain on top of the parent window at all times. To accomplish this I'm trying to pass the parent window as a parameter into the Show() method. Here's my code: Ribbon1.cs private void button2_Click(object sender, RibbonControlEventArgs e) { RangeSelectForm newForm = new RangeSelectForm

How to disable popups when opening a file using Microsoft.Office.Interop

拈花ヽ惹草 提交于 2019-12-17 18:34:57
问题 Such as read-only confirm, other alerts. What to do with these popups? Or ignore them? 回答1: See my answer here. Basically, you disable all alerts via the "Display Alerts" method: Microsoft.Office.Interop.[OFFICE_APP].Application app = new Microsoft.Office.Interop.[OFFICE_APP].Application(); app.DisplayAlerts = false; where [OFFICE_APP] is the name of the Office program you're using, such as Word, Excel, etc. 回答2: Here is another alternative to prevent the Security message asking you to allow

Unable to cast COM object - Microsoft outlook & C#

强颜欢笑 提交于 2019-12-17 18:28:11
问题 I have written this code to view the unread items in my outlook mail box and here is the code: Microsoft.Office.Interop.Outlook.Application app; Microsoft.Office.Interop.Outlook.Items items; Microsoft.Office.Interop.Outlook.NameSpace ns; Microsoft.Office.Interop.Outlook.MAPIFolder inbox; Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application(); app = application; ns = application.Session; inbox = ns.GetDefaultFolder(Microsoft.Office.Interop

How to eliminate warning about ambiguity?

孤街醉人 提交于 2019-12-17 16:24:14
问题 I have this warning: Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit'. Using method group. on my line wordApplication.Quit(); I have tried replacing it with: wordApplication.Quit(false); // don't save changes and wordApplication.Quit(false, null, null); // no save, no format but it keeps giving me this warning. It's not a huge problem because the

Get instance of Excel application with C# by Handle

妖精的绣舞 提交于 2019-12-17 06:06:14
问题 I have a c# simple application that have to write some values in a excel ranges of a specific worksheet. I create an instance of Excel application if not exist, but if exist i want to set active it and take an instance if it to use in my code. I use this code to create a new application: Microsoft.Office.Interop.Excel app = new Microsoft.Office.Interop.Excel.Application(); app.Visible = true; To get the handle of active excel window i use this api [DllImportAttribute("User32.dll")] private

How to read an excel file in C# without using Microsoft.Office.Interop.Excel libraries

我与影子孤独终老i 提交于 2019-12-17 02:58:55
问题 I have a .Net-Windows application in C#. I need to open an excel and process it. How can I do this without using Microsoft.Office.Interop.Excel libraries? 回答1: var fileName = @"C:\ExcelFile.xlsx"; var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\""; ; using (var conn = new OleDbConnection(connectionString)) { conn.Open(); var sheets = conn.GetOleDbSchemaTable(System.Data

Is using Interop the recommended method when auto-generating Office documents?

二次信任 提交于 2019-12-16 18:05:42
问题 As stated in the title, I need to do some C# coding from a Web Application that will auto-generate a Word document. So far, targeted towards Office 2007 and above users. My question would be, is using the Interop library the recommended way of doing this? Isn't there some issues with using it between different versions (e.g. 2007 -> 2010 -> 2013)? What are its advantages and disadvantages? And finally, are there any better alternatives? 回答1: On the contrary, Microsoft's advice is very much

Execution freezing while checking if Word is Visible

无人久伴 提交于 2019-12-14 03:47:37
问题 I'm check to see if Word is still visible before I perform certain tasks. The problem is execution just freezes after I close Word 2010 on the check of the visibility. Does not occur with 2007. //Initializing Word and Document While(WordIsOpen()) { } //Perform Post Close Tasks public bool WordIsOpen() { if(MyApp.Application.Visible)//Execution just freezes at this line after Word is not visible return true; else return false; } Anyone see this issue before? Is there a better way to check this

Obtaining Excel worksheet reference by worksheet name via C#

巧了我就是萌 提交于 2019-12-14 03:40:11
问题 I'm currently obtaining a handle to a Excel worksheet by using the below C# code: Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(15); //Get the worksheet "SubSignOff" number Is there any way that I can obtain the same by using the worksheet name "SubSignOff" ? 回答1: Instead of the using Excel.Workbook.Sheets collection, it's easier to access the Excel.Workbook.Worksheets collection, that way you can utilize early binding. In your case, it could look something like the following: