excel-interop

Reading Data From Excel SpreadSheet - Cannot perform runtime binding on a null reference

六眼飞鱼酱① 提交于 2019-12-22 17:56:03
问题 I have the code below to read data from an excel file, the problem I am running into is that when I try to read the range data, I get an exception "Cannot perform runtime binding on a null reference" on this line if (Int32.TryParse(xlRange.Cells[1, 4].Value2.ToString(), out value)) What I want to know is how I do access the information in the range properly please. Thanks in advance void ReadFromExcelToGrid2(String fileNameString) { try { Microsoft.Office.Interop.Excel.Application xlApp = new

Workaround to see if Excel is in cell-edit mode in .NET

老子叫甜甜 提交于 2019-12-22 12:25:14
问题 I have an application written in VB.NET that interacts with Excel via interop. I eventually ran into the known issue of Cell-edit mode (see MSDN and stackoverflow for some background). I have been trying to convert the suggested code to VB.NET but keep getting the following error: Reference required to assembly 'office, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' containing the type 'Microsoft.Office.Core.CommandBars'. Add one to your project. (BC30652) - E:\ ... .vb

Read Excel First Column using C# into Array

我的未来我决定 提交于 2019-12-22 07:08:06
问题 I'm trying to read in the values of the first column into an array. What's the best way to do that? Below is the code I have so far. Basically I'm trying to get the range of data for that column so I can pull the cell values into a system array. Microsoft.Office.Interop.Excel.Application xlsApp = new Microsoft.Office.Interop.Excel.Application(); if (xlsApp == null) { Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");

Microsoft.Office.Interop.Excel: How to Apply a border to ONE CELL

守給你的承諾、 提交于 2019-12-22 05:02:23
问题 I am looking to apply a border to one cell using the Microsoft.Office.Interop.Excel library. I am running a while-loop that is search for a empty cell within a certain column, once the cell is found I want to apply a border to it. I know there many forums on this using Ranges, but I can't use the range functionality since I do not know what cell it is being applied to exactly. My idea was: (Excel.Range)xlWS.Cells[row,1].Borders.LineStyle = (Whatever Value); Any advice? (besides links to other

Cannot open Excel file in C#

假如想象 提交于 2019-12-21 07:56:35
问题 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 " +

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

大城市里の小女人 提交于 2019-12-21 05:24:11
问题 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 回答1: 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

excel interop alternative

送分小仙女□ 提交于 2019-12-20 20:40:13
问题 I have started using the Excel interop assemblies that are provided by Microsoft for one of my C# applications. Everything is going fine, but there seems to be a lack of strong typing, and honestly it feels like I am writing VBA code. Are there any alternative ways to interact with Excel from C# that would give a better OO experience? I am using VS2010 and .Net 4.0 by the way. 回答1: Take a look at the EPPlus project over at Codeplex: http://epplus.codeplex.com/ I recently used this and it

How to close-without-save an Excel /xlsm workbook, w/ a custom function, from C#

北战南征 提交于 2019-12-20 16:24:54
问题 I have an Excel workbook with a custom non-time-dependent cell function that I am opening from a C# WindowsForms application using Interop.Excel. I read four values from it, perform no explicit changes/calculations, then close it from C#. When I try to directly close (without saving), I get a save prompt. I suspect this is because Excel is interpreting auto-recalculation on open as creating a change, even though nothing actually numerically or formulaically changes. I also set Excel

How to close-without-save an Excel /xlsm workbook, w/ a custom function, from C#

两盒软妹~` 提交于 2019-12-20 16:23:43
问题 I have an Excel workbook with a custom non-time-dependent cell function that I am opening from a C# WindowsForms application using Interop.Excel. I read four values from it, perform no explicit changes/calculations, then close it from C#. When I try to directly close (without saving), I get a save prompt. I suspect this is because Excel is interpreting auto-recalculation on open as creating a change, even though nothing actually numerically or formulaically changes. I also set Excel

Class not registered error when creating Excel workbook in C#

北战南征 提交于 2019-12-20 10:19:25
问题 When I try to access an Excel spreadsheet using the following code I get a "Library not registered' error when defining the workbook object wrkbuk using C# from Visual Studio 2012 with Office 2007 (ver 12) installed Microsoft.Office.Interop.Excel.Application excapp = new Microsoft.Office.Interop.Excel.Application(); string bookname = @"C:\Users\Public\Documents\RECRUITMENT & SELECTION\MOVEMENTS\MOVEMENTS\Miscellaneous Documents\VacanciesREAL.xls"; Workbook wrkbuk = excapp.Workbooks.Open