excel-interop

.Net Interop Excel ExportAsFixedFormat() Exception HResult: 0x800A03EC

大城市里の小女人 提交于 2019-11-28 12:07:04
问题 I'm currently implementing a method that generated multiple sheets and export them as PDF. For this I'm using the Microsoft.Office.Interop Library (v14.0.0.0) with .NET 4.5.2 . Running Office is 2016 My code: Dim excel As New Application() excel.Visible = False excel.DisplayAlerts = False Dim workbooks As Workbooks workbooks = excel.Workbooks Dim workbook As Workbook = workbooks.Add(Type.Missing) [...] workbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, String.Format(<a Path>)

.NET 4.0 Excel Interop issues with dynamic collections

核能气质少年 提交于 2019-11-28 11:32:51
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 loop. Trying to access the value directly using values[1] , neither when cast as a dynamic. The values

Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))

孤者浪人 提交于 2019-11-28 10:41:28
I am trying to convert a .xls file to an .xlsx file on the server-side using Microsoft.Office.Interop.Excel.Workbook class as follows: workBook.SaveAs("FILENAME_HERE", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing); and I get the following error: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005

Accessing an open Excel Workbook in C#

孤人 提交于 2019-11-28 09:31:29
I need to access an excel file that is already open. I thought just inspecting the .Workbooks property that it would be there but it isn't. What is the right way to get a reference to the open workbook? var app = new Microsoft.Office.Interop.Excel.Application(); // the count is 0 =( app.Workbooks.Count == 0; EDIT I can get a reference to the Excel Application via... app = (Excel.Application)Marshal.GetActiveObject("Excel.Application"); but app.Workbooks.Count is still 0 why isn't it able to get a reference to the opened workbook? Instead of instantiating a new instance, check for an existing

Exporting Several XtraGrid Controls to a Single Excel File

无人久伴 提交于 2019-11-28 06:27:23
问题 I've got several XtraGrid Controls each one containing different information, I get some information about the way in which you can export a XtraGrid to an Excel file in the following direction http://www.devexpress.com/Support/Center/p/Q362120.aspx Now Is there any way to export the each XtraGrid Control to a single Excel file so that every XtraGrid information is exported to a different excel sheet. I tried setting the exporting path direction to the same Excel file, but when the first

Excel Get_Range with multiple areas

我们两清 提交于 2019-11-28 03:31:32
问题 I'm trying to get a range from Excel, which has multiple areas specified, essentially I've got... int StartColumn int EndColumn int[] ColumnsToSkip When you combine these it's possible to produce a range with non-contiguous areas. Unfortunately I can't quite figure out the call to get this... MSDN isn't very useful... WorkSheet sheet; sheet.get_Range( what goes in here??? ); Anyone provide any help? Cheers. 回答1: A very simple solution is to specify different areas in comma-separated form:

How to rename excel sheet name dynamically in C#

早过忘川 提交于 2019-11-28 03:13:54
问题 I have created an excel workbook with many sheets like sheet1, sheet2,... etc. How can I rename these tab names dynamically in C#? 回答1: You didn't spedify how do you access the excel file. However, example from here might be useful for you if you're using Microsoft.Office.Interop.Excel . Note that it opens first sheet in the file, line: (Worksheet)xlBook.Worksheets.get_Item(1) using Excel = Microsoft.Office.Interop.Excel; object oMissing = System.Reflection.Missing.Value; Excel

Set cell value using Excel interop

笑着哭i 提交于 2019-11-27 23:16:25
问题 Ok, so I'm trying to set the value of a cell with the excel interop library. I am able to do it with the following: sheet.Cells[row, col] = value; but it's terribly slow for how many I'm setting. So I'm trying to go this route: Range excelRange = sheet.UsedRange; excelRange.Cells.set_Item(row, col, value); The code executes, but no data is put in the cell. Any suggestions on what I'm missing? Thanks! 回答1: Your first method should work fine for any reasonable (and a lot of unreasonable)

Safely disposing Excel interop objects in C#?

青春壹個敷衍的年華 提交于 2019-11-27 22:13:56
i am working on a winforms c# visual studio 2008 application. the app talks to excel files and i am using Microsoft.Office.Interop.Excel; to do this. i would like to know how can i make sure that the objects are released even when there is an error? here's my code: private void button1_Click(object sender, EventArgs e) { string myBigFile=""; OpenFileDialog openFileDialog1 = new OpenFileDialog(); DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. myBigFile=openFileDialog1.FileName; Excel.Application xlApp; Excel.Workbook

Getting excel application process id

痞子三分冷 提交于 2019-11-27 16:29:35
问题 I am creating an excel application with c#. Since I will maintain the excel file in urgency I want to keep its handler open. I want to keep the excel process id so I will be able to kill it in case the system crashs. How can I get the Excel Pid when creating it? 回答1: using Excel = Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices; using System.Diagnostics; class Sample { [DllImport("user32.dll")] static extern int GetWindowThreadProcessId(int hWnd, out int lpdwProcessId);