excel-interop

Export data from Windows Forms DataGridView and TextBox to Excel

孤街浪徒 提交于 2019-12-11 12:22:03
问题 I have a Form that contains number of TextBox controls and a DataGridView . I want to export the data from that form to an excel file. I am using this code it work perfectly for DataGridView but I don't know how to export TextBox controls data. private void copyAlltoClipboard() { dataGridView1.SelectAll(); DataObject dataObj = dataGridView1.GetClipboardContent(); if (dataObj != null) Clipboard.SetDataObject(dataObj); } try { copyAlltoClipboard(); Microsoft.Office.Interop.Excel.Application

Excel chart - Not getting Legends

天大地大妈咪最大 提交于 2019-12-11 11:49:29
问题 I am creating an excel chart using C# (interop). I am using get_Range function to get it from the data sheet in excel. I am getting the graph properly. But I am not getting the Legend names next to graph, it is coming as series0, series1. I am using folowing code. Range chartRange; Object misValue = System.Reflection.Missing.Value; ChartObjects xlCharts = (ChartObjects)sheet0.ChartObjects(Type.Missing); ChartObject myChart = (ChartObject)xlCharts.Add(10, 70, 250, 250); Chart chartPage =

Opening password protected Excel file in C++ or C# prompts for password even though I've passed an argument for password

风格不统一 提交于 2019-12-11 11:24:16
问题 I'm using the Microsoft.Office.Interop.Excel to open an password protected Excel file from my C++/CLI program. I supply a password as the 5th argument. When I run my program, Excel starts and opens my file but it prompts for password. Note that the file is password protected, not the worksheets. According to the documentation the password should be of type object but supplying it as a literal should also work? using namespace System; using namespace Microsoft::Office::Interop::Excel;

How can I programmatically create an Excel “sort/Filter combobox”?

折月煮酒 提交于 2019-12-11 10:29:10
问题 I'm reverse-engineering a manually created spreadsheet for dynamic creation. Most of the cells are populated with simple data, but there are a couple that are "sort/Filter" dropdowns like so: How can I dynamically create such a control? Is there a way to "view source" in the Excel spreadsheet to see what sort of code might be required to produce these controls? UPDATE Adapting MacroMark's code, this compiles: var rangeMonthYears = _xlSheet.Range[_xlSheet.Cells[7, 3], _xlSheet.Cells[7, 15]];

How to optimize exporting data to excel in Excel Interop?

北慕城南 提交于 2019-12-11 09:34:54
问题 I am using Excel interop to create excel workbooks from my query results. When there are thousands of records it takes a long time for the workbook to be generated. The below code is a sample of how I am populating the cells. RowNo = 1 For i = 1 To 4000 ColNo = 1 For j = 1 To 5 Dim cell As excel.Range = ws.Cells(RowNo, ColNo) Dim value = j cell.Value = value ColNo = ColNo + 1 Next RowNo = RowNo + 1 Next For the above code to run it takes more than a minute. How can I optimize it? 回答1: Found

Duplicate an Excel chart and move it to another sheet

半腔热情 提交于 2019-12-11 03:56:42
问题 I am using the C# Excel interop and I want to create a copy of a chart from one sheet but I want this copy on another sheet. I have tried the following: Excel.ChartObject chartTemplate = (Excel.ChartObject)sheetSource.ChartObjects("chart 1"); object o = chartTemplate.Duplicate(); Excel.ChartObject chart = (Excel.ChartObject)sheetSource.ChartObjects("chart 2"); chart.Name = "Skew" + expiry.ToString("MMMyy"); range = sheetDestination.Range["T" + chartRowCoutner.ToString()]; chart.Chart.Location

How can I force a cell to stop editing in Excel interop?

谁说胖子不能爱 提交于 2019-12-11 03:24:50
问题 I have an Excel 2007 add-in with a ribbon. One of the buttons in the ribbon triggers heavy manipulations of the current worksheet and I set various Excel.Application properties like Interactive and EnableEvents to false during the manipulations for speed and UX reasons. My problem is that the ribbon doesn't steal focus so if the user was editing a cell when he clicks my ribbon button, an exception is thrown when setting Application.Interactive = false because Excel considers the user is still

Microsoft.Interop object won't quit or “release”

谁都会走 提交于 2019-12-11 02:49:48
问题 Everytime I run this code, the object won't close. I still have an excel.exe running in the task manager. Even if I set the objects = null, still nothing. I've even tried using the objects .Quit() method. What am I doing wrong here? private bool ValidateQM() { //setup the objects Excel.Application oXL = null; Excel.Workbook oWB = null; Excel.Worksheet oSheet = null; int hWnd = 0; try { //Start Excel and get Application object. oXL = new Excel.Application(); hWnd = oXL.Application.Hwnd; oXL

Excel hangs at the point where the message box asks if I want to save the workbook

牧云@^-^@ 提交于 2019-12-11 02:41:26
问题 I've got a Class report witch includes a method RunExcelReporting . It knows what workbook to open and what routines to run via a control table. As a test I've just spelled one of the macros incorrectly in the control table. The console application creates an instance of report and runs the RunExcelReporting method but then stops at a point where Excel is diplaying the message box which asks if the user would like to save the workbook. This is a bad halfway house point for me - I'd rather

Excel Interop Apply Chart Template

狂风中的少年 提交于 2019-12-11 02:26:47
问题 Problem Overview: I am automating the report generation (excel) for a customer using C# with "native" excel support (microsoft.office.interop.excel) and the EPPlus library. My customer is not very flexible about charts design so my charts must have the exact same style as theirs. No problem, i exported their chart templates using Excel 2010 What does not work: I can't apply any chart template via code What i have tried: 1 - EPPlus : Have no support for loading templates to charts 2 -