excel-interop

Returning value from Excel VBA function is always null

橙三吉。 提交于 2019-12-13 03:52:07
问题 I'm attempting to run excel vba macro and get back result but I'm always getting back null (excuse my ignorance, I'm new to this macros) the macro Public Function TestMacro() As Boolean If Len(Range("A1").Value) <> 9 Then TestMacro = False Else TestMacro = True End If End Function the c# code invoking it Excel.Application excelApp = new Excel.Application { DisplayAlerts = false }; object misValue = Missing.Value; excelApp.Visible = false; Excel.Workbook ExcelWorkBook = excelApp.Workbooks.Open

DisconectedContext was detected

☆樱花仙子☆ 提交于 2019-12-12 15:17:30
问题 I need help getting rid of this error: "Transition into COM context 0x465608 for this RuntimeCallableWrapper failed with the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)). This is typically because the COM context 0x465608 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else. Releasing the interfaces from the current COM context (COM context 0x465498). This may cause corruption or data loss.

How can I format a formulaic result in C# Excel Interop?

让人想犯罪 __ 提交于 2019-12-12 13:26:30
问题 I've got this code that sums the values in the given range (Column O Row 10 to Column O the last signficant row): Note: That's the letter "O" not the number "Zero". var totalTotalPackageCountCell = (Range)_xlSheetDelPerf.Cells[curDelPerfRow + 2, TOTAL_PACKAGE_COUNT_COLUMN]; totalTotalPackageCountCell.Formula = string.Format("=SUM(O10:O{0})", curDelPerfRow); It works pretty dandy except for one thing: the value displays without commas, such as "20192" (I want it to be "20,192"). I tried this:

Microsoft Interop: Excel Column Names

微笑、不失礼 提交于 2019-12-12 10:33:34
问题 I am using Microsoft Interop to read the data. In excel-sheet the column-names are like A,B,C,D,....,AA,AB,.... and so on. Is there any way to read this column-names? If you need any other info please let me know. Regards, Priyank 回答1: Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open("workbookname"); Excel.Worksheet xlWorksheet = xlWorkbook.Sheets[1]; // assume it is the first sheet int columnCount = xlWorksheet.UsedRange.Columns.Count; List

file not found comException error

*爱你&永不变心* 提交于 2019-12-12 05:27:47
问题 I am trying to save a jpg file into an excel document. I am getting the exception System.Runtime.InteropServices.COMException{"The specified file wasn't found"} now the file does exist and is located at C:\test\101.jpg here is my code Imports Excel = Microsoft.Office.Interop.Excel Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As

How can I get this PivotTable to display the values I want it to, in the location I want them to be?

China☆狼群 提交于 2019-12-12 05:22:18
问题 After much gnashing of teeth, &c, I was able to achieve a modicum of success with generating a PivotTable. It now sports both a "row filter" (on the Descriptions) and a "column filter" (on the "month year" columns), like so: This is accomplished with the following code: var pch = _xlBook.PivotCaches(); Range sourceData = _xlBook.Worksheets["PivotData"].Range["A1:G318"]; // TODO: Make range dynamic PivotCache pc = pch.Create(XlPivotTableSourceType.xlDatabase, sourceData); PivotTable pvt = pc

C# - Transpose excel table using Interop

不羁岁月 提交于 2019-12-12 04:43:14
问题 I should transpose a table of an excel sheet in c#. There is a method to do it into the Microsoft.Office.Interop.Excel api, or any other method to do this? Edit This is my code: string pathFile, range; pathFile = @"C:\Users\Administrator\Desktop\" + fileName; Excel.Application app = new Excel.Application(); Excel.Workbook book = app.Workbooks.Open(pathFile); Console.WriteLine("Inserire il range delle celle da copiare(sono tutti uguali): "); range = Console.ReadLine(); Excel.Range rgn = app

open excel file as readonly from process start

送分小仙女□ 提交于 2019-12-12 03:36:18
问题 I have to open an excel application using the Process.Start method. Current code is below. startInfo.FileName = "EXCEL.EXE"; startInfo.Arguments = "\"C:\\Shared\\Some Directory\\File Name 2016.xlsm"; var res = Process.Start(startInfo); I only need read access to the file. However if another user has the file open a window prompt pops up asking if I would like to open the file in read only mode. Is there anyway using the Process.Start method to specify that the file only needs to be opened as

How to get and set excel column width through c# excel interop

主宰稳场 提交于 2019-12-12 03:22:04
问题 I am using excel interop in creating excel. Now, I have to get the size of a column as basis of what the next column's size would be. I tried the following code: width = xlWorksheet.Range[xlWorksheet.Cells[1, 4], xlWorksheet.Cells[1, 11]].Width; xlWorksheet.Columns[5].ColumnWidth = width; width_of_first_col = xlWorksheet.Range[xlWorksheet.Cells[1, 1], xlWorksheet.Cells[1, 1]].Width; xlWorksheet.Columns[6].ColumnWidth = width_of_first_col; The result should be column 4 and column 5 have the

Sort Excel table (ListObject) on protected sheet using Excel Interop

眉间皱痕 提交于 2019-12-12 03:06:37
问题 Sorting Excel tables (ListObjects) is not allowed on protected sheets. You'll see the following error message: I spent weeks looking for a solution with no success. Everything out there is outdated with Excel 2007 code samples. There are no tutorials or guides on how circumvent this limitation. Here's how I was able to finally overcome.. 回答1: There is no trappable event when sorting from the Excel's filter drop-down menu of a table. You can, however, trap the events when an ascending,