interop

Why Application.get_Caller(Type.Missing) returns a negative integer?

╄→гoц情女王★ 提交于 2019-12-12 04:43:41
问题 There's something weird about get_Caller(Type.Missing) method. It returns a negative integer, -2146826265 , instead of the Range object as it should. Has anyone come across this issue before? Why is that and how should I solve it? Thanks. Excel.Range range = (Excel.Range) application.get_Caller(System.Type.Missing); The above code would fail if I try to explicitly user type Excel.Range . The error message says, 'Cannot convert type 'int' to 'Microsoft.Office.Interop.Excel.Range'. EDIT: The

How insert multiple hyperlinks to one comment in MS WORD using C#?

我与影子孤独终老i 提交于 2019-12-12 04:17:29
问题 This is my code. I can insert one hyperlink to per comment but i want insert multiple hyperlinks to one comment but i don't know how change my code. using Microsoft.Office.Interop.Word; public void addCommentsToDocument(object start, object end, Hyperlink[] comments) { Range range = document.Range(ref start, ref end); object missing = System.Reflection.Missing.Value; for (int i = 0; i < comments.Length; i++) { object url = comments[i].url; object text = comments[i].Text; Comment var =

Fastest way to write cells to Excel

孤街醉人 提交于 2019-12-12 04:13:08
问题 I am writing a function to export data from a gridview to Excel this method on VB .NET: Call consultaPlanilha() Dim i, j As Integer 'CONTADORES ReDim vetPontos(GridPontos.Rows.Count - 2, 1) For i = 0 To GridPontos.Rows.Count - 2 For j = 0 To 1 vetPontos(i, j) = CDbl(GridPontos.Item(j, i).Value) xlw.Application.Cells(i + 3, j + 2).Value = vetPontos(i, j) Next Next xlw.Save() This is taking a long time for large amounts of data. Is there a faster way to write a lot of data to Excel at once?

excel interop : NumberFormat #,##0.000 doesn't display the expected result

孤者浪人 提交于 2019-12-12 03:54:10
问题 I developed a C# utility class called ExcelGenerator that generate a List of objects to excel. I want to display double numbers in this format : 3 288,523. NumberFormat = "#,##0.000" doesn't display the expected result This is the method : public void FormatNombre(string frm) { _excel.Selection.NumberFormat = frm; } and this is the call : eg.FormatNombre("#,##0.000"); Number still displayed like this : 3288,522.542 回答1: You want to format 3288523.542 to 3 288,523? Try something like this: [

Getting maximum row/column number from Excel Range

拥有回忆 提交于 2019-12-12 03:00:01
问题 I have a certain Range , for example: Range rng = activeWorksheet.Range["A1", "B50"]; I've been retrieving the maximum row and column number used in this Range by looping through it and assigning a row number to my variable, but there must be a better way? I've been doing this: int maxRow = 0; foreach (Range row in rng.Rows) maxRow = row.Row; 回答1: I think I found the most elegant solution for this, something like this: int maxRow = rng.Row + rng.Rows.Count - 1; int maxColumn = rng.Column +

What is the best practise to relase Excel interop objects in C#? [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-12 02:46:16
问题 This question already has answers here : How do I properly clean up Excel interop objects? (41 answers) Closed 6 years ago . I have a function basically to convert an excel file to text file. The structure is like following. What I am concerned is the Finally part? Is it a best practise to kill the excel? Excel.Application excel=new Excel.Application(); Excel.Workbook wb=excel.Workbooks.Open(…); Try { … Foreach(Excel.Worksheet sheet in wb.Sheets) { … Marshal.RealseComObject(sheet); } … }

Marshaling Delphi 5 OleVariant to C#

二次信任 提交于 2019-12-12 02:33:37
问题 I'm trying to use some legacy Delphi 5 DLLs from C# (2.0/3.5). Some of the exported functions are declared as such: function SimpleExport: OleVariant; stdcall; function BiDirectionalExport(X: OleVariant; var Y: OleVariant): OleVariant; stdcall; I wish to set these up as delegates using Marshal.GetDelegateForFunctionPointer, but I'm having trouble getting the data Marshaled correctly. I'm using kernel32 imports of LoadLibrary and GetProcAddress, so I'm relying on GetDelegateForFunctionPointer

How do I catch an Interop exception?

十年热恋 提交于 2019-12-12 02:22:29
问题 I am trying to catch an Interop Exception in my C# code IEngine engine = null; try { engine = engineLoader.GetEngineObject(AbbyySdkSerialNumber); } catch(System.Runtime.InteropServices.COMException ex) { int i = 0; } but it does not want to jump into catch block. Any ideas? Thank you in advance! 回答1: The CLR automatically maps the HRESULT from COM interop to more specific managed exceptions, not to COMException . For example, E_ACCESSDENIED becomes UnauthorizedAccessException , E_OUTOFMEMORY

P/Invoke. How to call unmanaged method with marshalling from C#?

你。 提交于 2019-12-12 02:09:49
问题 I've got a problem with P/Invoke. I'm calling .dll (implemented on c++) from c# code. There is a class, that contains the next methods: virtual AudioFileList *API CreateAudioFileList ()=0; virtual bool API DisposeAudioFileList (AudioFileList *iAudioFileList)=0; AudioFileList class looks like: virtual bool API GetFile (long index, std::string *oPath, AudioFileInfo *fileInfo)=0; virtual long API GetNumberFiles ()=0; So, the question is how can I call CreateAudioFileList method and than pass the

How can i add a button to all windows explorer instances?

久未见 提交于 2019-12-12 01:56:03
问题 I am trying to add a button to one of the existing tool bars in any windows explorer instance. After much research i figured out that BHO (browser helper objects) are the best way to hook to windows explorer. My question is : Is that the correct way to go about it ? In the SetSite of the BHO i get the comObject that is the explorer window. What now ? If i can get the hWnd of the explorer window can i use win API to add my button ? Note i am developing in C# for XP. Thanks. 回答1: 1 In pre-XP