excel-interop

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

元气小坏坏 提交于 2019-11-27 14:25:46
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 class 'Castle.Proxies.ListRowProxy'. This exception implies that I forgot to setup the appropriate property

Writing to an existing Excel File using c#

*爱你&永不变心* 提交于 2019-11-27 14:14:31
问题 I am trying to open (or create a new xls) Excel file and write some values to it. Although, the program below works just fine if I simply create a new xls file, I encounter the some problem in line **mWorkBook = oXL.Workbooks.Open (path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);** Here's the error: 'LOG.xls' cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only. It

How to fix 'Microsoft Excel cannot open or save any more documents'

牧云@^-^@ 提交于 2019-11-27 12:55:57
问题 I am running C# ASP.NET 4.5 web application on Windows 7 64-bit using IIS 7.5. The application pool it uses has the name 'ASP.NET v4.0' and its identity is ApplicationPoolIdentity. The application uses MS Office Interop (Microsoft Excel 14.0 Object Library). At line wBook = wBooks.Add(Missing.Value); , it throws the following error: Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk space. u2022 To make more memory available, close

Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?

≡放荡痞女 提交于 2019-11-27 09:05:30
The following code leaves a Microsoft Excel background process running, until after my program has exited: var excelApplication = new Application(); var workbooks = excelApplication.Workbooks; var workbook = excelApplication.Workbooks.Open(file.FullName); workbook.Close(); excelApplication.Workbooks.Close(); excelApplication.Quit(); Marshal.ReleaseComObject(workbook); Marshal.ReleaseComObject(workbooks); Marshal.ReleaseComObject(excelApplication); Why? What am I missing? Got it! application.Workbooks != application.Workbooks This property doesn't expose a variable, it generates a value. So

Eliminating use of '2 dots' when using Excel Interop Com Objects - C#

流过昼夜 提交于 2019-11-27 08:32:36
问题 I am having trouble releasing Excel Interop Com Objects which is causing my c# application to crash when I attempt to save and then close an Excel workbook created via Excel Interop. I feel the issue is that in some cases I am using '2 dots' with excel interop COM objects which from what I've read is not allowed. I have eliminated 2 dots from most lines of code, but I am having troulbe figuring out a way to recreate the following lines of code so that they only use one dot. If anyone has any

Why would the Excel Interop remove an image after processing a file?

泄露秘密 提交于 2019-11-27 07:56:25
问题 Excel Interop is removing images from processed files. I’m using the Excel Interop, no third-party components are present (that I'm aware of). The workflow is -- create a copy (target) of a file (template), populate cells, change radio-button state Create copy (target) of a pre-existing .xslm file (template) Open target via Excel Interop Populate target cells, change radio-button state The worksheet with an image is not modified Close target On my dev machine, the target file looks great --

microsoft.interop.excel Formatting cells

五迷三道 提交于 2019-11-27 07:39:33
问题 I am building a report using the microsoft.interop.excel library in C#. I have something like this: Range rangeTarget; . . . rangeTarget = worksheet.get_Range("C" + row, "N" + row); I want the range to display its values as whole numbers i.e. with no decimal places. I've tried rangeTarge.AutoFormat, but have no idea how to use it. Any Ideas ? Thanks. 回答1: see MSDN Microsoft.Office.Tools.Excel.NamedRange namedRange1 = this.Controls.AddNamedRange(this.Range["A1", "A5"], "namedRange1");

How to iterate through Excel Worksheets only extracting data from specific columns

感情迁移 提交于 2019-11-27 07:03:59
问题 How do you iterate through an excel workbook with multiple worksheets only extracting data from say columns "C", "E" & "F"? Here is the code I have thus far: public static string ExtractData(string filePath) { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workBook = excelApp.Workbooks.Open(filePath); string data = string.Empty; int i = 0; foreach (Excel.Worksheet sheet in workBook.Worksheets) { data += "******* Sheet " + i++.ToString() + " ********\n"; //foreach (Excel

How to generate a chart from an Excel sheet?

前提是你 提交于 2019-11-27 06:30:40
问题 I can generate an Excel file when I pass a datatable into the below function: public static void ExportDataTableToExcel(DataTable dt, string filepath) { object missing = Type.Missing; object misValue = System.Reflection.Missing.Value; //create excel Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //add excel workbook Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Add(); //add worksheet to workbook Microsoft.Office.Interop

Get all worksheet names in plaintext from Excel with C# Interop?

只谈情不闲聊 提交于 2019-11-27 06:01:27
问题 I'm using VS2010 + Office Interop 2007 to attempt to get a few specific spreadsheet names from an Excel spreadsheet with 5-6 pages. All I am doing from there is saving those few spreadsheets I need in a tab delimited text file for further processing. So for the three spreadsheet names I get, each one will have its own tab delimited text file. I can save a file as tab delimited just fine through Interop, but that's assuming I know what the given page name is. I have been informed that each