excel-interop

Attach to existing Excel Instance

穿精又带淫゛_ 提交于 2019-12-05 13:45:55
I'm trying to determine whether or not an instance of Excel of running with a particular file open, and if so attach to it so I can control that instance. I've searched around and the majority of what I've got have come from this question. It has a reference to another site , but unfortunately it's dead for me so I cannot read up on it. My code so far is; //Is Excel open? if (Process.GetProcessesByName("EXCEL").Length != 0) { Process[] processes = Process.GetProcesses(); foreach (Process process in processes) { //Find the exact Excel instance if (process.ProcessName.ToString() == "EXCEL" &&

Exporting Excel Charts as Images

扶醉桌前 提交于 2019-12-05 12:58:52
I've written the following simple C# console application to export all the charts from an Excel Workbook. It works just fine unless the chart has not been scrolled to since opening the document , in which case an empty image file is generated. using Excel = Microsoft.Office.Interop.Excel; using System; using System.Diagnostics; namespace ExcelExporter { class ChartExporter { const string EXPORT_TO_DIRECTORY = @"C:\Users\Sandy\Desktop\Excel\Charts"; static void Main(string[] args) { Excel.Application app = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application") as Microsoft

Excel worksheet in Windows form application without opening Excel application

和自甴很熟 提交于 2019-12-05 09:47:23
问题 I am converting several VBA projects to Windows form applications. The only problem I have is that some of the functionality of Excel is essential to the application, such as R1C1 formulas. I do not want to instantiate the Excel application or access saved worksheets. All of the data is retrieved by querying Oracle databases. 2-Dimensional arrays are not an option because the columns contain differing datatypes, and DataGridViews are too slow to work with. I thought simply dimming a Microsoft

Microsoft.Office.Interop.Excel: How to Apply a border to ONE CELL

青春壹個敷衍的年華 提交于 2019-12-05 05:28:30
I am looking to apply a border to one cell using the Microsoft.Office.Interop.Excel library. I am running a while-loop that is search for a empty cell within a certain column, once the cell is found I want to apply a border to it. I know there many forums on this using Ranges, but I can't use the range functionality since I do not know what cell it is being applied to exactly. My idea was: (Excel.Range)xlWS.Cells[row,1].Borders.LineStyle = (Whatever Value); Any advice? (besides links to other forums, I already looked through tons of forms)? Excel.Range range = xlWS.UsedRange; Excel.Range cell

(object[,])range.get_Value(XL.XlRangeValueDataType.xlRangeValueDefault) causes a conversion error

天涯浪子 提交于 2019-12-05 02:29:37
问题 Error: Cannot convert type 'string' to 'object[*,*]' That's the error I have been getting. Can someone give me some pointers so that I can avoid it? Thanks. Note: Interestingly, (object[,])range.get_Value(XL.XlRangeValueDataType.xlRangeValueDefault) will only produce this bug when range.Count == 1 . It works fine when count is equal to and above 2. sample code: object[,] arrValue; //global variable private string[] createFormulaCollection() { ArrayList s = new ArrayList(); try { //look at the

Add Picture in Excel on Particular Cell with C#

大兔子大兔子 提交于 2019-12-04 19:55:02
I am trying to add an image into Excel cell at row 3 column 1 as specified below. The compiler gave me an error. Did I do something wrong here? Thanks in advance for your suggestions. Excel.Application xlApp; Excel.Workbook wb; Excel.Worksheet ws; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); wb = xlApp.Workbooks.Add(misValue); ws = (Excel.Worksheet)wb.Worksheets.get_Item(1); ws.Cells[3, 1] = ws.Shapes.AddPicture("C:\\photos\\4a.png", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 75, 75, 350, 50); you have to add

Excel exception HRESULT: 0x800A03EC from ChartArea.Copy()

旧街凉风 提交于 2019-12-04 19:36:22
I'm working on a C# Application thats interacts with an Excel instance using excel interop.dll v11.0. I'm using the following code to copy a chart from the excel worksheet to the clipboard: public Image ReadChart(Chart chartAccess) { try { Microsoft.Office.Interop.Excel.Worksheet sheet = workbook.Sheets[chartAccess.Sheet.Name]; Microsoft.Office.Interop.Excel.ChartObject chart = sheet.ChartObjects(chartAccess.Name); chart.Chart.ChartArea.Copy(); // exception gets thrown here return System.Windows.Forms.Clipboard.GetImage(); } catch (COMException) { // display error dialog etc... } This worked

How to properly clean up Excel interop object in C#, 2012 edition

依然范特西╮ 提交于 2019-12-04 13:17:26
问题 I am in the process of writing an application in C# which will open an Excel spreadsheet (2007, for now) via interop, do some magic, then close. The "magic" part is non-trivial, so this application will contain many references to many COM objects spawned by Excel. I have written this kind of application before (too many times, in fact) but I've never found a comfortable, "good smell" approach to interacting with COM objects. The problem is partly that, despite significant study, I still don't

Proper way of closing Excel application

蓝咒 提交于 2019-12-04 07:00:32
问题 I'm writing an application, which accesses Excel file with this code: RBTApplication = new Excel.Application(); RBTWorkbooks = RBTApplication.Workbooks; RBTWorkbook = RBTApplication.Workbooks.Open( RBTDataSet.Instance.FilePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0 ); RBTWorksheet = (Excel.Worksheet)RBTWorkbook.Worksheets.get_Item( 1 ); RBTRange = RBTWorksheet.UsedRange; After I load data that I need, I try to close

How do I merge multiple excel files to a single excel file

纵饮孤独 提交于 2019-12-04 06:50:20
问题 So I was trying to make an excel sheet aggregator. In my line of work we get people who send us a bunch of individual excel files that are all related each with only 1 sheet used. I was following to some degree this previous post's ideas. But upon doing so, some of the excel sheets I copied were coming up blank. Only certain ones. I have no idea why some are blank and others are fine. Here is the code I use to open and copy the excel files OpenFileDialog browse = new OpenFileDialog(); browse