excel-interop

How to Open; SaveAs; then Close an Excel 2013 (macro-enabled) workbook from PowerShell4

戏子无情 提交于 2019-12-18 17:53:05
问题 Doing a search on the above Com operations yields links dating to '09 and even earlier. Perhaps it hasn't changed but I find myself bumping up against errors where 'it is being used by another process.' - even though no Excel app is open on my desktop. I have to reboot to resume. To be clear - I'm trying to open an existing file; immediately SaveAs() (that much works), add a sheet, Save(); Close() - and then, importantly, repeat that cycle. In effect, I'm creating a few dozen new sheets

Create UDF using VSTO and no VBA

亡梦爱人 提交于 2019-12-18 11:37:57
问题 Similar to this question (but in my case not VSTO SE), however, I just want to confirm that it is not possible to create a UDF using pure VSTO in Visual Studio 2005 and Excel 2003 - so, to absolutely clear, my question is: Is it possible to create a Excel 2003 UDF using Visual Studio 2005 and a VSTO solution without using any VBA or other tricks? I'm aware of ManagedXLL, ExcelDNA, Excel4Net etc but don't want to consider those for the moment. Thanks 回答1: Concerning whether there is a way

WinForms COM Exception opening Excel workbook

流过昼夜 提交于 2019-12-18 09:24:33
问题 I'm writing a very basic WinForms app using VB.Net, everything is going smoothly until I try and open an Excel file that I've written to the tempLocation via a Stream object (The workbook is in my project resources and the build action is set to "Embedded Resource") Here's the code that causes the error: Dim xlWBTemp As Excel.Workbook Dim xlApp As Excel.Application '// Below resolves to "C:\Users\MacroMan\LockTemplate.xlsm" Dim tempLocation As String = Environ("USERPROFILE") & "\LockTemplate

Microsoft.Office.Interop.Excel or EPPlus for read a huge (or not) Excel file

送分小仙女□ 提交于 2019-12-18 09:14:49
问题 I wrote a code to read a column from a Excel file. I use Microsoft.Office.Interop.Excel on this, first read the entire Range and then write in System.Array after that I do some operations with the System.Array values and finally I convert it to List because I fill a ListBox element. This is the code (only relevant parts): private List<string> bd = new List<string>(); private static System.Array objRowAValues; private List<string> bl = new List<string>(); private static System.Array

How to release excel process?

白昼怎懂夜的黑 提交于 2019-12-18 07:06:18
问题 I'm using the Excel interop and it seems to be creating a process every time I call new Microsoft.Office.Interop.Excel.Application() And never ending the process even though I call xlApp.Quit(); How can I get the processes to end? 回答1: Are you releasing all of your references? (Which means you have to save them in the first place). For example here's what's in my dispose from some excel interop(): public void Dispose() { if(!this.disposed) { if(cell != null) Marshal.FinalReleaseComObject(cell

.NET 4.0 Excel Interop issues with dynamic collections

别等时光非礼了梦想. 提交于 2019-12-17 19:52:02
问题 In Excel you can return a dynamic array System.Object[*] , from a series object using XValues . In .NET 3.5 you can access the elements in this object by casting it to and array, i.e.: var values = (Array)series.XValues; In .NET 4.0, this no longer works, and the message "Unable to cast object of type 'System.Object[*]' to type 'System.Object[]'" is given. Any ideas? The following doesn't work: Casting it as dynamic. Casting it to a System.Object[*] . Just placing the object in a for each

Moq & Interop Types: works in VS2012, fails in VS2010?

此生再无相见时 提交于 2019-12-17 11:48:29
问题 I have a .NET library project with about 500 unit tests. All these tests run fine in Visual Studio 2012. However, some of my tests fail in Visual Studio 2010. In these failing tests, I use Moq to mock several Interop Types from Microsoft.Office.Interop.Excel . The test fails immediately when attempting to access these mocked interop types: Error: Missing method 'instance class Microsoft.Office.Interop.Excel.Range [ExcelAddIn.Core] Microsoft.Office.Interop.Excel.ListRow::get_Range()' from

How do I import from Excel to a DataSet using Microsoft.Office.Interop.Excel?

北慕城南 提交于 2019-12-17 06:26:33
问题 What I want to do I'm trying to use the Microsoft.Office.Interop.Excel namespace to open an Excel file (XSL or CSV, but sadly not XSLX) and import it into a DataSet. I don't have control over the worksheet or column names, so I need to allow for changes to them. What I've tried I've tried the OLEDB method of this in the past, and had a lot of problems with it (buggy, slow, and required prior knowledge of the Excel file's schema), so I want to avoid doing that again. What I'd like to do is use

Cannot close Excel.exe after Interop process

梦想的初衷 提交于 2019-12-17 04:29:47
问题 I'm having an issue with Excel Interop. The Excel.exe doesn't close even if when I realease instances. Here is my code : using xl = Microsoft.Office.Interop.Excel; xl.Application excel = new xl.Application(); excel.Visible = true; excel.ScreenUpdating = false; if (wordFile.Contains(".csv") || wordFile.Contains(".xls")) { //typeExcel become a string of the document name string typeExcel = wordFile.ToString(); xl.Workbook workbook = excel.Workbooks.Open(typeExcel, oMissing, oMissing, oMissing,

Cannot close Excel.exe after Interop process

跟風遠走 提交于 2019-12-17 04:29:12
问题 I'm having an issue with Excel Interop. The Excel.exe doesn't close even if when I realease instances. Here is my code : using xl = Microsoft.Office.Interop.Excel; xl.Application excel = new xl.Application(); excel.Visible = true; excel.ScreenUpdating = false; if (wordFile.Contains(".csv") || wordFile.Contains(".xls")) { //typeExcel become a string of the document name string typeExcel = wordFile.ToString(); xl.Workbook workbook = excel.Workbooks.Open(typeExcel, oMissing, oMissing, oMissing,