excel-interop

Retrieve Excel application from process id

不羁岁月 提交于 2019-12-12 02:49:16
问题 I am starting an Excel application using the Process class. I am able to get the process id & the main window handle with the code below. Process xlP = Process.Start("excel.exe"); int id = xlP.Id; int hwnd = (int)Process.GetCurrentProcess().MainWindowHandle; So this starts an Excel application. How do I reference this particular instance of Excel with the process id & main window handle? I have seen similar questions on here but the answer was a link to a webpage that no longer exists. I

How to wrap merged Excel content beyond a specified length?

南楼画角 提交于 2019-12-12 02:23:35
问题 I have a column in my Excel spreadsheet whose contents I spread (merge) over four rows like so: private void AddDescription(String desc) { int curDescriptionBottomRow = _curDescriptionTopRow + 3; var range = _xlSheet.Range[_xlSheet.Cells[_curDescriptionTopRow, ITEMDESC_COL], _xlSheet.Cells[curDescriptionBottomRow, ITEMDESC_COL]]; range.Merge(); range.Font.Bold = true; range.VerticalAlignment = XlVAlign.xlVAlignCenter; range.Value2 = desc; } I later Autofit the columns to be just wide enough

C# : Excel : Determine if a string is a valid Range reference?

核能气质少年 提交于 2019-12-12 02:06:23
问题 How would this VB function will look like as C# ? The goal is to determine if a string ref represents a valid datasheet Excel.Range . This isn't a trivial VB to C# conversion as Range can't be constructed. Private Function IsRange(ref) As Boolean ' Returns True if ref is a Range Dim x As Range On Error Resume Next Set x = Range(ref) If Err = 0 Then IsRange = True Else IsRange = False End Function Best 回答1: I would have liked to find a way to not have to rely on an exception for checking the

HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG), error, my website is on azure cloud

陌路散爱 提交于 2019-12-12 00:50:34
问题 This error is coming when i am writing excel file thru c# code using interop from website url. It is working perfectly fine on local machine. after running publish of my website to Azure Cloud base server. It is not working on website url. If i have to install MS Excel on Azure, how can i do that. and If there is any other solution, please guide me. 回答1: E_CLASSNOTREG is "Class not registered". You are likely using the Office Interop Assemblies, which require the appropriate version of Office

Excel Process will not terminate with Excel-Introp

人盡茶涼 提交于 2019-12-11 17:59:46
问题 I have been trying to import data from an excel sheet into a DataTable . The problem is that after i finish, excel would not terminate the process. I do not want to terminate by process name using System.Diagnostics as that approach would terminate all excel instances rather than the one that was created by the application. I know that this question was posted over here before multiple times, but none of the solutions seem to work for me. I am probably missing something and can not see it.

How can I build a project containing Excel creation in VSTS?

邮差的信 提交于 2019-12-11 17:04:04
问题 I have a project that uses Interop Excel to build up a report. This runs just fine and the report is created every time. The problem that I'm facing now is when published, I'm not able to run it, it is built and published but I get an exception when I try to create the Excel file with this line: var excelApp = new Excel.Application(); The exception is the one below, I've added multiple references to assemblies but I'm not sure if maybe I'm missing some COM reference for this to run. Unhandled

Excel.Interop DisplayAlerts to false does not handle everything

拟墨画扇 提交于 2019-12-11 16:27:14
问题 Ok i tried looking on here to find this before, but no luck. The problem I'm having is when two programs try to either save, close, or interact in anyway with a single excel workbook at the same time a dialog box appears. The dialog boxes says something like "[file path] Is currently in use and can not be accessed." I have DisplayAlerts set to false, but it will not catch this. Has anyone else had this problem and have a viable solution? 回答1: The file is currently in use is due to OS throwing

Why does this code insert a blank row between two rows written (C# Excel Interop)?

吃可爱长大的小学妹 提交于 2019-12-11 13:47:00
问题 In my C# (.NET 4.5) Windows Forms app using Excel Interop, I adapted the code from here like so (removing redundant things grayed out by Resharper, and add "Type." before the "missing" args (and changing their case to upper): private void WriteListObjectTestSheet() { _xlSheetPlatypus.Cells[5, 1] = "Apple"; _xlSheetPlatypus.Cells[6, 1] = "Strawberry"; _xlSheetPlatypus.Cells[7, 1] = "Cashew"; _xlSheetPlatypus.Cells[8, 1] = "Kumquat"; _xlSheetPlatypus.Cells[9, 1] = "Pomegranate";

c# excel Interop.XlDVType.xlValidateList AutoComplete IncellDropDown

試著忘記壹切 提交于 2019-12-11 13:12:18
问题 I am able to get dropdown in a cell using the code below Interop.Range validationAddressRange = ws.Worksheet.get_Range(startAddress, endAddress); validationAddressRange.Select(); validationAddressRange.Cells.Validation.Delete(); validationAddressRange.Cells.Validation.Add(Type: Interop.XlDVType.xlValidateList, AlertStyle: Interop.XlDVAlertStyle.xlValidAlertStop, Formula1: formula); validationAddressRange.Cells.Validation.IgnoreBlank = true; validationAddressRange.Cells.Validation

Modify Interop Excel for Opening Existing File

喜夏-厌秋 提交于 2019-12-11 13:06:23
问题 I'm using Excel Interop for C# to export a datagridview to Excel and print it. I'm using this code: try { Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Application.Workbooks.Add(true); int ColumnIndex = 0; int rowIndex = -1; foreach (DataGridViewRow row in dataGridView1.Rows) { rowIndex++; ColumnIndex = 0; foreach (DataGridViewColumn col in dataGridView1.Columns) { ColumnIndex++; excel.Cells[rowIndex + 1, ColumnIndex] = row.Cells