excel-interop

Get Cell Value in Excel from Range

↘锁芯ラ 提交于 2019-12-04 06:24:27
问题 How can I extract the value of a cell from a range object? It seems like it should be simple. This Stackoverflow question and answers did not really help. Here is what I want to do but it fails every time with an exception on row.columns(0,0). Dim rdr = oFindings.Range For Each row As Excel.Range In rdr.Rows Dim Account = row.Columns(0,0).value2.tostring ' Do other stuff Next To make it work I had to implement this code: For Each row As Excel.Range In rdr.Rows ndx = 0 For Each cell As Excel

Basic of XLL Excel Addin - Need to invoke a C# API from Excel [closed]

大兔子大兔子 提交于 2019-12-04 06:13:56
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am quite new to creating excel addins. Earlier I used to create a tlb for .NET libraries. I used to make my .NET class COMVISIBLE and create a Com callable wrapper and register as a tlb to call from Excel (using regasm). I now have a math library written in C#. Got to know there

Cannot open Excel file in C#

匆匆过客 提交于 2019-12-04 03:10:06
I have the following C# function in my project, which is supposed to open and return an existing Excel workbook object: Application _excelApp; // ... private Workbook OpenXL(string path, string filename) { try { if (_excelApp == null) { _excelApp = new Application(); } Workbook workBook = _excelApp.Workbooks.Open(path + filename, // Name 0, // Do not update links true); // Open read-only return workBook; } catch (Exception e) { _excelApp = null; throw new ArgumentException("Error opening " + path + filename, e); } } But when I run it with "C:\" and "scratch.xlsx", the Open() call throws the

Microsoft.Office.Interop.Excel.ApplicationClass has no constructor defined

佐手、 提交于 2019-12-03 23:23:23
问题 I tried to follow How to open an Excel file in C# tutorial, i.e. added a reference on the Com tab to Microsoft Office 14.0 Object Library and tried to compile code: using Excel = Microsoft.Office.Interop.Excel; //... Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; xlApp = new Excel.ApplicationClass();//error here //... and faced a compile-time error, saying There is no constructor defined for Microsoft.Office.Interop.Excel.ApplicationClass type. What am I

Excel worksheet in Windows form application without opening Excel application

大憨熊 提交于 2019-12-03 21:33:58
I am converting several VBA projects to Windows form applications. The only problem I have is that some of the functionality of Excel is essential to the application, such as R1C1 formulas. I do not want to instantiate the Excel application or access saved worksheets. All of the data is retrieved by querying Oracle databases. 2-Dimensional arrays are not an option because the columns contain differing datatypes, and DataGridViews are too slow to work with. I thought simply dimming a Microsoft.Office.Interop.Excel.Worksheet object would be enough, but the program kept failing and upon

(object[,])range.get_Value(XL.XlRangeValueDataType.xlRangeValueDefault) causes a conversion error

喜欢而已 提交于 2019-12-03 20:09:01
Error: Cannot convert type 'string' to 'object[*,*]' That's the error I have been getting. Can someone give me some pointers so that I can avoid it? Thanks. Note: Interestingly, (object[,])range.get_Value(XL.XlRangeValueDataType.xlRangeValueDefault) will only produce this bug when range.Count == 1 . It works fine when count is equal to and above 2. sample code: object[,] arrValue; //global variable private string[] createFormulaCollection() { ArrayList s = new ArrayList(); try { //look at the currently active excel sheet //iterate through cells (not Null) and find the one contains IES(...) /

Adding hyperlinks in Excel[2007] in C# - Within Excel it self

故事扮演 提交于 2019-12-03 17:15:18
问题 Can anybody tell me how we can add a hyperlink in Excel (2007 or later) from a cell in one sheet to a cell in another sheet using Office Interop in .NET (c#) For example: A hyperlink from Sheet1 Cell A1 to Sheet2 Cell B10 回答1: What you want to use here is the Hyperlinks.Add method. You can call it with code that looks something like this: Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1]; Excel.Range rangeToHoldHyperlink = worksheet.get_Range("A1", Type.Missing); string

Find bitness (32-bit/64-bit) from Excel Application object?

老子叫甜甜 提交于 2019-12-03 16:46:39
Is it possible to determine whether Excel is running in 32-bit or 64-bit from the Microsoft.Office.Interop.Excel.ApplicationClass? Edit The solution should work for both Excel 2010 and Excel 2007 This code should give you the "bitness" of Excel. Microsoft.Office.Interop.Excel.ApplicationClass app = new Microsoft.Office.Interop.Excel.ApplicationClass(); if (System.Runtime.InteropServices.Marshal.SizeOf(app.HinstancePtr) == 8) { // excel 64-bit } else { // excel 32-bit } EDIT: here is another version that should work for previous versions of Excel as well. Just pass an ApplicationClass reference

Adding buttons to spreadsheets in .NET (VSTO)

北战南征 提交于 2019-12-03 12:37:11
Using VSTO or some related technology, is it possible to programmatically embed a button in a cell of an Excel worksheet, and configure it to call a C# function when it is clicked? How? Thanks. With a VSTO document customization (i.e., a Workbook with .Net code attached), you can add and remove controls at runtime to the Worksheets of the project. The following code illustrates the idea: public partial class Sheet1 { private void Sheet1_Startup(object sender, System.EventArgs e) { var button = this.Controls.AddButton(10, 10, 50, 50, "My Button"); button.Text = "My Button"; button.Click += new

How to properly clean up Excel interop object in C#, 2012 edition

天涯浪子 提交于 2019-12-03 08:23:43
I am in the process of writing an application in C# which will open an Excel spreadsheet (2007, for now) via interop, do some magic, then close. The "magic" part is non-trivial, so this application will contain many references to many COM objects spawned by Excel. I have written this kind of application before (too many times, in fact) but I've never found a comfortable, "good smell" approach to interacting with COM objects. The problem is partly that, despite significant study, I still don't perfectly understand COM and partly that the interop wrappers hide much that probably shouldn't be