Click here to Skip to main content
15,891,136 members
Everything / Interop

Interop

interop

Great Reads

by Leif Simon Goodwin
How to pass strings between managed and unmanaged code
by Christ Akkermans
An introduction to the strange world of mixed language programming with FORTRAN and C# .NET code
by Debabrata_Das
This article will talk about how a WCF service can be consumed by a Java client application.
by koolprasad2003
This article explain you How to protect word document using C# and Word automation

Latest Articles

by ToughDev
How to convert OFT to .NET Windows Form in VS
by William Damert
Console .NET application using Microsoft.Office.Interop.Word for keyword search
by Lee P Richardson
Which SPA technology should you use: Blazor WebAssembly or something more mature like Angular, and why?

All Articles

Sort by Updated

Interop 

6 Jul 2023 by LiterallyGutsFromBerserk
I want to merge a range of 3 cells for each row where the first cell and the last cell are set to "", however it does not seem to work for me. What I have tried: I tried doing it for all the rows whether the first and third cell are blank or...
23 Jun 2023 by Graeme_Grant
Recommended method of doing work from C# was given here: Export datagridview to excel while keeping the formatting[^]: 1. Create a Macro recording of the actions that you wish to perform 2. View the VBA code generated for you 3. Use the VBA code...
23 Jun 2023 by Richard MacCutchan
You have already posted this question at Merge cells from different columns in a datagridview C#[^], and been given a number of suggestions. If you have additional informationor questions then please use the Improve question link below the...
7 May 2023 by Member 15990780
Working with upload function, using FileUpload Control and I'm trying to cleanse some data to avoid the duplication by using replace/ update the existing file by scanning the datetag, dateuntag, tag and tagtype to replace/ update the entire row...
6 Feb 2023 by Shawn Work
The problem is a bit vague, sorry. However, I believe setting your CharSet attribute (auto), does not sound like it's working. Check out Marshal.SystemDefaultCharSize (If 2 then Unicode, otherwise Ascii), try CharSet=Unicode on the attribute,...
20 Dec 2022 by EstKells
Hello, so I get data from an SQL Query and load the data into an Excel File. At first the amount of data is to big to use Interop because the loading would take 5 minutes or something. So I load the data from the SQL Query in an new Excel file...
20 Dec 2022 by Richard Deeming
Rather than using Interop (which will be slow, requires that you have Office installed, and won't work from an "unattended" application[^]) or generating a CSV file and "pretending" that it's a real Excel file, try generating a proper Excel file...
15 Nov 2022 by Manojkumar-dll
i have created a word automation project which working fine in local were as if i install in windows server its not working and shows failed due to class not registered and researched in internet that word automation will not work if MS Office...
15 Nov 2022 by CHill60
The documentation states (bold mine)Quote: All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not...
3 Nov 2022 by RickZeeland
To get the week number you can use: Calendar.GetWeekOfYear() See: Calendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) Method (System.Globalization) | Microsoft Learn[^] Here is some code from the CodeProject article Converting Numbers...
3 Nov 2022 by Manojkumar-dll
Hello everyone i have created a word automation and email sending project (Sorry for my poor english) which automatically put the values according to the variables i have placed but for each week i have to renmae it like...
29 Sep 2022 by EstKells
So I have an Program in which I load Data from an Excel File. The User can write the cell he want to edit, for example: "B3" is wanted to edit. With this Information I want to take Data from another Column for example C2 and with the Data From...
4 Aug 2022 by 0x01AA
One can address a specific cell directly by row/column index. E.g. like firstTable.Rows[1].Cells[1].Range.Text = "My Value for that Cell"; Note: Keep in mind that for office interop the index of a collection starts at '1' and ends at...
4 Aug 2022 by Manojkumar-dll
I want to insert values into the cells of the table in my word file in c# using Microsoft interop and i have used foreach in the below code for dummy number that automatically insert as per the cell position i want to repace with it my own values...
4 Aug 2022 by Richard MacCutchan
You just need a set of data (an array or collection) that you want to put in the cells. So replace (cell.RowIndex - 3 + cell.ColumnIndex).ToString() with each item of your data.
6 Jul 2022 by EstKells
I want to Export Data from an DataTable to an Excel sheet. I use this to enable the Hyperlinks: oWB.SaveAs(path + "newsletter.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,...
30 Nov 2021 by Richard Deeming
Load the data into a single DataSet: private static DataTable LoadTable(string connectionString, string query, string tableName) { using (var connection = new OdbcConnection(connectionString)) using (var command = new OdbcCommand(query,...
30 Nov 2021 by Manidas Payyoli
Hi, I have 3 data table I wanto export those data tables in to sheet 1 ,sheet 2 ,sheet 3()need to give A,B,C as sheet name also) How we can achive this ? when i was trying i am getting as different seperate excel(by duplicating the code multiple...
31 Aug 2021 by Manidas Payyoli
I know i have another options to delete the column but ,how we can fix these kind of error? object does not contain definition for delete in excel interop 'object xlWorksheetNew.Columns["P:Q"].Delete(); object does not contain definition for...
31 Aug 2021 by Wendelius
One thing is to re-check the type of xlWorksheetNew is it correctly defined. Another thing is that if you want to cast the columns before Delete is called, you need to apply parenthesis. In other words...
6 Jun 2021 by Fazil13
I'm trying to do an interop to a C# structure from C++. The structure c# public static IntPtr tempNode = IntPtr.Zero; and also i am using Marshal.PtrToStructure, Marshal.PtrToStringAuto as per requirement. now i am trying with 64bit compiled...
6 Jun 2021 by Richard MacCutchan
See the notes to the Example at Marshal.PtrToStructure Method (System.Runtime.InteropServices) | Microsoft Docs[^] concerning 64-bit.
4 Mar 2021 by William Damert
Console .NET application using Microsoft.Office.Interop.Word for keyword search
15 Feb 2021 by amirea
I need to keep references in unmanaged code to objects on managed side, like handles. There are going to be approx. 10,000,000 objects. I'm not familiar with interop, initially I thought it was as simple as declaring ref SomeClass on C# side...
15 Feb 2021 by KarstenK
You shouldnt do that this way, but really think hard about using so many objects at once. If you really need that heavy load than you better code the program in one language to get best performance with that many objects. Else you can use the...
8 Feb 2021 by FullStackVale
In Windows form Application, Facing this exception System.Runtime.InteropServices.COMException (0x800A03EC): Cannot insert object. at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[]...
9 Aug 2020 by Lee P Richardson
Which SPA technology should you use: Blazor WebAssembly or something more mature like Angular, and why?
3 Aug 2020 by Member 14904864
There is a table on the website and users enter data in the cells of the table. I edited the ready codes to pull the data entered by each user to different pages as follows. But the problem is: there are a lot of(2000) cells and I have to match...
3 Aug 2020 by Sandesh M Patil
https://www.codeproject.com/Questions/65930/How-to-export-textbox-values-to-excel-sheet
2 Aug 2020 by Sandeep Mewara
Well, you can try to export using JavaScript. Not the exact solve but would give you direction enough to get started: Import and Export Outlook Appointments (using JavaScript)[^] You would need to find the excel equivalent and then try to...
2 Aug 2020 by Dave Kreskowiak
You cannot use Office Interop in an ASP.NET application. It's not supported because Office does not support "re-entrancy". That means multiple session interactions to Excel can fail. Sure, it'll owrk perfectly fine on your dev machine. You're...
21 Jul 2020 by Dilan Shaminda
Hi, I am using using Microsoft.Office.Interop.Word; assembly in order to access the word files and do some stuff. I want to know is there any way that I can get the character position where the cursor is currently in. What I have tried: Below is the code I use Object wordObject = null; ...
21 Jul 2020 by Member 12734776
Hello you use this for get cursor position range First must active document word_application.Selection.Range
23 Mar 2020 by phil.o
Arrays in C# are zero-base indexed. This means that, for an array of N elements, these elements are indexed from 0 to N-1, not from 1 to N. In your code, each time you are indexing, you are using 1-based indices. You should correct that and see...
23 Mar 2020 by Member 14781099
We are using Excel Interop in C# for Excel sheets formatting. The issue is ,I am getting above exception when i run an excel (2000kb). the weird thing is every time i get exception in different pages . Exception is not consistent. When i run an...
23 Mar 2020 by OriginalGriff
Quote: Page means sheet I dont know which line exactly ,because in a sheet there will be 1000 rows to debug and exception behavior is not consistent. If you are going to learn to develop code, you need to know the terminology and use it...
6 Feb 2020 by Fred Andres
Thanks for your help Maciej. With your information I was able to come up with the following solution which is lightening fast: public void find_and_replace_text(string curr_text, string new_text) { Word.Find findObject; var missing = Type.Missing; ...
6 Feb 2020 by Fred Andres
I wrote the following code to find the location of a text string in a word document. It works but it is glacially slow. How do I speed it up? public int find_text(string some_text) { int point0; int location; int text_length; ...
5 Feb 2020 by Maciej Los
As you mentioned, you have to use Find method. See: Find and replace text in documents programmatically - Visual Studio | Microsoft Docs[^] How to: Programmatically loop through found items in documents - Visual Studio | Microsoft Docs[^] How to: Programmatically restore selections after...
8 Dec 2019 by Lucas Martins de Souza
Hello guys,I'm allways searching stuff around here, and almost all the time I find what I need.But right know I need something a little more specific and I can't find it on google neither here.I have a big code on FORTRAN 77. With a bunch of subroutines and functions. And I want to...
8 Nov 2019 by amrinde
you should use save as oDoc.SaveAs("MyFile.doc", ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
15 Oct 2019 by dashingly
I am getting "HRESULT: 0x800A03EC" error when running Excel add-in with following code: Excel.Range rng = ActiveSheet.Cells[x, y] as Excel.Range; string before = rng.Value2; string cleanV = System.Text.RegularExpressions.Regex.Replace(before, @"\s+", ""); ...
22 Aug 2019 by IamWsk
How to get "Footer row"(Sum or Count) of a Access Form (DataSheet) I search the Total rows in Form Controls but I am not getting anything for it. What I have tried: ACCESS.DoCmd.OpenForm("FormName"); ACCESS.Controls cntrls = (ACCESS.Controls)app.Forms["FormName"].Controls;
26 Apr 2019 by abdul subhan mohammed
Dear All, I have created winform application which evaluates Microsoft word. Here, my application top position is 470 and I want to set Microsoft word bottom equal to the top position of my application, that is, 470. What I have tried: I tried this code: if (handle != IntPtr.Zero) ...
27 Mar 2019 by Maciej Los
This is bad idea, bad approach! Anything VBA code can do with Excel objects, C# is able to do the same. Note, taht C# offers much more than VBA, for example: Linq.
27 Mar 2019 by Member 12766428
While calling macro in excel from c# code , i get this exception System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC What I have tried: I use Microsoft.Office.Interop.Excel version 15 and the client machine has Office 2000 and while calling macro , i...
18 Jan 2019 by DavidMorf
Hi all, I've made a custom datagridview with Excel export functionality and stumbled upon a problem I can't seem to fix. I'm trying to format the excel columns according to their datatype and giving an array to the Microsoft.Office.Interop.Excel object. When my grid column is of any of the...
18 Jan 2019 by Maciej Los
Check this: Range.NumberFormat property (Excel) | Microsoft Docs[^] and this: MS Excel: How to use the FORMAT Function with Numbers (VBA)[^] For decimals with 2 places after dot: columnRange.NumberFormat = "#,##0.00" 'keeps format: ' .803 => 0.80 ' 1.224 => 1.22 '55.556 => 55.56 For...
7 Dec 2018 by Matthew Menard
I'm trying to change the series names of my line chart in Excel. I'm using C# (interop) to create the chart. This is what I have so far: Excel.Range xvalues = myWorkSheet.Range["R3", "R5"]; Excel.Range values1 = myWorkSheet.Range["S3", "S5"]; Excel.Range values2 = myWorkSheet.Range["T3",...
7 Dec 2018 by Matthew Menard
What I didn't put in the code, was the fact that I position the legend within the chart area. I had set the myChart.Legend.Height, myChart.Legend.Left and myChart.Legend.Top properties. I figured that I didn't need to set the Legend.Width property, as I thought that the legend would...
13 Nov 2018 by M. Faisal Hafeez
I'm trying to open a existing PowerPoint slide in WPF program. I would like to view and edit .ppt file in WPF window at same time.Further I want to embed annotated notes on slides(Like ink in MS-Word) and save these notes along slides for future use. After editing .ppt file should be compatible...
13 Nov 2018 by Aydin Homay
Hi, What comes to my mind is the use of office development in visual studio which allows you to embed office (word, excel, power point) inside of your wpf or winform application. See the below link for more information. Office client development | Microsoft Docs[^] Another links: Embedding MS...
9 Oct 2018 by abdul subhan mohammed
Hi Guys, I have windows application with Microsoft word interoperability c#. This application is used to Evaluate Actions done in ms-word by a user. I have to create one template to Evaluate Paragraph TabStops used in the word document. What I have tried: wordApplication.ScreenUpdating =...
9 Oct 2018 by Richard Deeming
Replace: foreach(WordInterop.TabStops t in abc) with: foreach(WordInterop.TabStop t in abc) NB: TabStop, without the trailing "s". TabStop Interface (Microsoft.Office.Interop.Word) | Microsoft Docs[^]
29 Aug 2018 by Richard MacCutchan
c# load dll at runtime - Google Search[^]
29 Aug 2018 by TheRedEye
I need to use to interop features of a DLL in my WPF application, but without adding the DLL as a reference in my project. How would add this DLL at runtime and call a method in the DLL? What I have tried: The DLL's function works just fine if I add the DLL as a reference and call the method...
29 Aug 2018 by OriginalGriff
That's the right way to do it: if your code needs a .NET assembly, then adding a reference is the right way to do it. You can do it without, but it's a lot more complex, and makes your code a lot harder to read: C# - Execute code from a .NET DLL (Class Library) without referencing it? - Stack...
29 Aug 2018 by Member 13966307
In C# using Outlook = Microsoft.Office.Interop.Outlook, my solution looked like this: Outlook.NameSpace nameSpace = olApp.GetNamespace("Mapi"); Outlook.MAPIFolder inbox = (Outlook.MAPIFolder)nameSpace.Folders["The Shared Folder"].Folders["Inbox"];
29 Aug 2018 by Tisha Shaffer
I have the following code working well on my Development PC (Windows XP with Office 2010). But when I run the executable on a Windows 7 PC with Office 2010, I get the following error:"The operation failed because of a registry or installation problem. Restart Outlook and try again. If the...
12 Aug 2018 by Dilan Shaminda
I am using Win32 API functions to register the current program in the Clipboard chain. Below function retrieves the window handle of the current owner of the clipboard. The problem is GetCaptionOfWindow always return null. [DllImport("user32.dll")] public static extern IntPtr...
12 Aug 2018 by Richard MacCutchan
The GetWindowText function (Windows)[^] requires the second parameter to be the address of a memory buffer. You are passing s StringBuilder reference.
12 Aug 2018 by Mehdi Gholam
Read this : how to get GetWindowText[^]
11 Aug 2018 by Gerry Schmitz
DDESend Function - Access[^]
11 Aug 2018 by Dilan Shaminda
I know DDE is old fashion outdated technology. But I am creating a C# Windows Form application to send data to Excel file for research purpose. I use Win32 DDE functions and below is what I have tried so far. What I have tried: [DllImport("user32.dll", EntryPoint = "DdeInitialize")] public...
12 Jul 2018 by Michael Breeden
I'm converting an ASP Classic project to .Net, The original application uses something along the line of: this.oWord=GetObject("","Word.Application"); to display an instance of Word in an iframe using an ActiveX object. The web page contains controls to do fairly sophisticated control of the...
11 Jun 2018 by Maciej Los
Quote: I am using itextsharp dll in a C# project and I need to use the project in Microsoft Access. Not sure what you need... Do you want to register itextsharp.dll or c# project (exported to dll) in MS Access? If you want to use your c# project in VBA, i'd strongly recommend to read this:...
11 Jun 2018 by Member 13582266
I am using itextsharp dll in a C# project and I need to use the project in Microsoft Access. I need to be able to register the dll's for it to work but everytime I use regasm.exe I get "RegAsm : warning RA0000 : No types were registered". Is there anything way of registering itextsharp or is...
10 Jun 2018 by #realJSOP
All exposed classes and methods have have the comvisible attribute. If textsharp classes/methods don’t have that attribute, you’ll probably have to write a wrapper assembly that does it. I’m just guessing, I don’t know anything about itextsharp, and abhor MS Access and VBA.
5 Jun 2018 by alejandroGS
Hello everyone! I'm creating a program in WPF based on C #, which is filling rows of Excel in the same column, but the code on which I base the truth I could not make it work, so I ask a little help to guide me a bit. The example of filling in the data consists of row 15 to row 20 in the same...
30 May 2018 by Richard MacCutchan
How to use MS-Word clipborad instead of Windows clipboard in C#[^]
30 May 2018 by Dilan Shaminda
Hi, I did some research about Microsoft office clipboard and I couldn't find any API to access and read the office clipboard content. I know that I can read copied content from the system clipboard. But in my case I want to compare MS office clipboard content with the clipboard data I have. Is...
30 May 2018 by Gerry Schmitz
Your app openened a SECOND copy of the "active document" ... there is no meaningful cursor info.
22 May 2018 by Maciej Los
As far as i know - up to Word 2010 it's impossible... As MSDN states[^]: Word 2013: You can mark a document as read-only and still allow changes to selected parts. You can make these unrestricted parts available for anyone who opens the document, or you can grant permission to specific...
22 May 2018 by Leonardo Hernández
I have to insert a table, by code, using word.interop, but this have to be read only. this table will be into a Break page. So I need to know how do that. What I have tried: I have not tried nothing, just looking for information
14 Apr 2018 by Andy Galluzzi
Join me to create the most advanced yet most simple to use full duplex MMF based IPC for Windows
14 Feb 2018 by Haseeb4328
Hello, I want to read multiple worksheets which exist within same excel file. Following is my simple code which read first worksheet (by default), i want to read second as well. There will be change in argument but i don't know. Your help is highly...
19 Jan 2018 by Leo Hernández Núñez
I am currently working on a C # project using a WordAddIn, which inserts tables, there are some of these tables that must be created blocked or read only, since the information can not be modified. What I have tried: I I have not treated anything, so far, I'm in the case investigation
19 Jan 2018 by Dave Kreskowiak
As far as I know, Word doesn't support protecting individual elements in a document. It's either the entire document or nothing.
8 Nov 2017 by Ismael M.
A generic DLL that call any .NET DLL in VB6.
30 Oct 2017 by Dave Kreskowiak
You don't. IE and Firefox were the only browsers that supported ActiveX. You have no choice but to use software that is installed on the workstations if you're going to support more browsers. FF pulled support for ActiveX, I think, a year ago and IE's replacement, Edge, doesn't, and never...
30 Oct 2017 by Subratp10
I’ve a legacy VC++ ActiveX dll with UIs. This ActiveX dll can be used only in the same workstation but through browser (IE only, because of its other dependencies. Now there is a requirement from the customers that it should be accessible and behave same from other browsers like Chrome,...
11 Sep 2017 by Joe Doe234
HI, I have this code to insert into and excel sheet : try { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; ...
11 Sep 2017 by Richard MacCutchan
Try using _Application.Quit method (Microsoft.Office.Interop.Excel)[^].
21 Aug 2017 by ADS14
I am creating a exe to read and update a particular excel using Interop. This exe will be in share path accessed my multi users ,which means the excel will also be updated my multiple user at same time .. how to handle this programmatically in C# ? What I have tried: I am creating a exe to...
21 Aug 2017 by Graeme_Grant
Have a read of these: * c# - Multiple users writing concurrently to shared Excel file using OpenXML - Stack Overflow[^] * One Excel file, multiple editing users, live updates - Super User[^] * How to Make Excel Allow Multiple Users | Chron.com[^]
17 Aug 2017 by Dennis Wu CA
A demo that generates a simple Excel spreadsheet with subscripts and superscripts
2 Aug 2017 by abdul subhan mohammed
Dear All, I'm trying to read word file ".docx" and text file ".txt". For this i'm using this code: What I have tried: string[] linesFile = File.ReadAllLines(@"" + file, Encoding.UTF8);//word file Output "PK\u0003\u0004\u0014\0\u0006\0\b\0\0\0!\0ߤ�lZ\u0001\0\0...
2 Aug 2017 by Richard MacCutchan
You need to use the Microsoft.Office.Interop.Word namespace ()[^] to get the text from .doc/docx files.
2 Aug 2017 by Jochen Arndt
Word files are not text files. Old Word files (*.doc) are binary files using the MS compound file format. New files (*.docx) are zipped archives containing multiple files where most are XML files (there may be also binary image files for example). So you might unzip the docx file first and then...
27 Jul 2017 by Johnny_Liu
JointCode.Shuttle is a fast, flexible and easy-to-use service-oriented framework for cross-AppDomain communication. It's a replacement for MarshalByrefObject which is provided by the runtime libraries.
27 Jul 2017 by Johnny_Liu
JointCode.Shuttle is a fast, flexible and easy-to-use service-oriented framework for cross-AppDomain communication. It's a replacement for MarshalByrefObject provided by the runtime libraries.
13 Jul 2017 by Nick Reshetinsky
Hi guys!I want to export some functions from winmm.lib library ...I tried to use [DllImport] but it only works for dynamic libraries like kernel32.dll,wininet32.dll
13 Jul 2017 by Member 13309303
errdggdfgdfgdfgfgdfgdgdfgdfggdfgdfgdfgdfg
7 Jul 2017 by Leif Simon Goodwin
How to pass strings between managed and unmanaged code
22 Jun 2017 by Patrice T
I wonder why you are using those coordinates which is a GUI thing for users ? Why don't you tell your program to use directly the column number ? Excel.Range araAt = raporWrkS.cells(columnNumber,1); araAt.EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight,...
21 Jun 2017 by kozmikadam
Hi everyone, I'm working with Excel files on this days. I need to insert a column beetween some others. I'm using this code and it's works fine. Excel.Range araAt = raporWrkS.Range["K1"]; ...
21 Jun 2017 by kozmikadam
Here is the solution. First of all i get column count with a for loop. I count every column in this loop. Already have this loop also. And then convert the count of column to alphabetical version with this code. private string GetExcelColumnName(int columnNumber) { int dividend =...