excel-interop

how to set values to a two-dimensional Excel range?

社会主义新天地 提交于 2019-12-07 09:09:27
I need to build an excel sheet from a list of test-cases in a specific format in order to upload it it to the server. I've trubles to populate the two dimensional range of "expected" and "actual" in the file. I use the same methods in order to populate the headers, which is a one-dimensional array, and the steps (which is two-dims). The flow is: Defunding the TestCase range (some headers + steps). Let's say: A1 to E14 for the 1st iteration. Depunding a sub (local) range within the testCase range for the headers (e.g: A1 to C1). Depunding another sub (local) range within the testCase range for

Calling Application.Calculate breaks formula being edited

本小妞迷上赌 提交于 2019-12-06 13:16:54
问题 I'm working on an add-in that periodically requests a recalculation using the following: ((Excel.Application) xlApp).Calculate() If the user happens to be editing a formula at the time, Excel breaks the users formula when I do this. I expect the action to fail due to user activity, which it does, but not before oddly interrupting whatever formula the user is typing. For example, if the user is in the middle of typing into a cell =SUM(1+2+ , as soon as I run the above line of code, their input

Add Picture in Excel on Particular Cell with C#

一个人想着一个人 提交于 2019-12-06 12:25:09
问题 I am trying to add an image into Excel cell at row 3 column 1 as specified below. The compiler gave me an error. Did I do something wrong here? Thanks in advance for your suggestions. Excel.Application xlApp; Excel.Workbook wb; Excel.Worksheet ws; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); wb = xlApp.Workbooks.Add(misValue); ws = (Excel.Worksheet)wb.Worksheets.get_Item(1); ws.Cells[3, 1] = ws.Shapes.AddPicture("C:\\photos\\4a.png", Microsoft.Office

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

邮差的信 提交于 2019-12-06 11:56:35
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:3471 The original C# code (from previosuly mentioned articles) is as follows private bool IsEditMode() {

COMException (0x80010108 - RPC_E_DISCONNECTED) When Closing Excel.Workbook

霸气de小男生 提交于 2019-12-06 00:25:45
When I run the following code, I get the exception below: ''# NOTE: ExcelApp is a Private main form variable Dim ReportBooks As Excel.Workbooks = ExcelApp.Workbooks Dim ReportBook As Excel.Workbook = ReportBooks.Open(localFilename) Dim ReportSheet As Excel.Worksheet = ReportBook.Sheets("Report") ''# Retreive data from sheet ReleaseCOM(ReportSheet) ReportBook.Close(True) ''# Error raised here ReleaseCOM(ReportBook) ReleaseCOM(ReportBooks) ERROR: COMException was unhandled The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)) Note: All

C# Proper Way to Close Multiple Excel Objects With Excel Process Destroyed

与世无争的帅哥 提交于 2019-12-05 21:13:15
I have a C# console program. When it runs, it instantiates some Excel objects such as: (openExcelO). When the program is done running, I have a method to close down Excel (closeExcel) and that is supposed to properly clean up the Excel process. In task manager I can see the remnants of Excel that remain. The shut down routines were cobbled together from internet examples: private void openExcelO (string dir) { try { xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(dir + "PortfolioOptimization5.xlsm", 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform

Excel Interop: Creating instance with Task.Run results in exception System.EntryPointNotFoundException

送分小仙女□ 提交于 2019-12-05 19:49:38
Here is my minimal example producing the problem: using System.Runtime.InteropServices; using System.Threading.Tasks; using Excel = Microsoft.Office.Interop.Excel; class Program { static void Main(string[] args) { Task.Run(() => { Excel.Application app = new Excel.Application(); if (app != null) { app.Quit(); Marshal.FinalReleaseComObject(app); app = null; } }); } } This results in the following exception: The last part in Japanese says the "EventSetInformation" of DLL advapi32.dll entry point cannot be found . I'm having difficulty understanding what is going on. Basically why is this

Can you paste a block of cells in one shot using Excel Interop w/o using the clipboard?

喜夏-厌秋 提交于 2019-12-05 16:36:08
I'm trying to transfer data from a DataSet into an Excel workbook. Unfortunately, I need more control than I can get by simply linking to Excel via ADO.NET and using standard SQL to select and insert the data, so I'm using excel interop. My original algorithm involved looping through all the tables/rows/items of the data set and individually setting the Formula of each cell in Excel. This worked, but it was taking nearly half a minute to transfer all the data. I decided to try a different solution: convert each table to a tab-delimited string (using a combination of StringBuilder and string

Excel interop prevent showing password dialog

不羁的心 提交于 2019-12-05 16:00:03
问题 I am writing a program to clean excel files from empty rows and columns, i started from my own question Fastest method to remove Empty rows and Columns From Excel Files using Interop and everything is going fine. The problem is that i want to prevent excel from showing the password dialog when the workbook is password protected and to throw an exception instead of that . i am using the following code to open excel files using interop: m_XlApp = New Excel.Application m_XlApp.visible = False m

Strange error on Excel Workbook input

柔情痞子 提交于 2019-12-05 15:18:21
For the current code: String currentPath = Directory.GetCurrentDirectory(); OpenFileDialog op = new OpenFileDialog(); op.InitialDirectory = currentPath; if (op.ShowDialog() == DialogResult.OK) currentPath = op.FileName; else { toolStripStatusLabel1.Text = "Failed to Load Workbook"; toolStripStatusLabel1.Visible = true; } Workbook wb = new Workbook(excel.Workbooks.Open(currentPath)); I recieve the error: System.Runtime.InteropServices.COMException was unhandled Message=Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following