excel-interop

COM object excel interop clean up

 ̄綄美尐妖づ 提交于 2019-12-20 06:35:29
问题 Lets say that I have one component which is doing something with Workbook object and somewhere in the middle of that method body I have call to some method of another class. For example: public class MainComponent { public void MyMainMethod() { OtherComponent otherComponent = new OtherComponent(); Workbook document; // some work with workbook object // working with document and worksheet objects. otherComponent.MethodCall(document); // some work with workbook object and it's worksheets.

How to modify existing Excel file in vb.net

人走茶凉 提交于 2019-12-20 06:25:46
问题 I want to modify an existing Excel file. The following piece of code generates a duplicate modified excel file in documents folder instead of modifying the original file. Note: the file which I want to modify is not in the Documents folder Imports Microsoft.Office.Interop.Excel Public Class Form1 Public ExcelFolder As String Public selectedfile As String Public excel As Application Public workbook As Workbook Public sheet As Worksheet Public r As Range Public array(,) As Object Private Sub

How can I alter my PivotTable so that it displays the data in the desired way?

只谈情不闲聊 提交于 2019-12-20 04:58:14
问题 I've been able to drag a PivotTable out onto the dance floor, but haven't been able to get it to boogie down - it seems we keep stepping on each other's toes. I've got data already on the sheet from which to build the Pivot Table. This class describes that data: public class PriceVarianceData { public String Unit { get; set; } public String ShortName { get; set; } public String ItemCode { get; set; } public String Description { get; set; } public String PriceWeek { get; set; } public String

How to merge two excel files into one with their sheet names?

心不动则不痛 提交于 2019-12-20 04:32:08
问题 For merging of two excel sheet, I am using below code. using System; using Excel = Microsoft.Office.Interop.Excel; using System.Reflection; namespace MergeWorkBooks { class Program { static void Main(string[] args) { Excel.Application app = new Excel.Application(); app.Visible = true; app.Workbooks.Add(""); app.Workbooks.Add(@"c:\MyWork\WorkBook1.xls"); app.Workbooks.Add(@"c:\MyWork\WorkBook2.xls"); for (int i = 2; i <= app.Workbooks.Count; i++) { int count = app.Workbooks[i].Worksheets.Count

How to merge two excel files into one with their sheet names?

元气小坏坏 提交于 2019-12-20 04:31:39
问题 For merging of two excel sheet, I am using below code. using System; using Excel = Microsoft.Office.Interop.Excel; using System.Reflection; namespace MergeWorkBooks { class Program { static void Main(string[] args) { Excel.Application app = new Excel.Application(); app.Visible = true; app.Workbooks.Add(""); app.Workbooks.Add(@"c:\MyWork\WorkBook1.xls"); app.Workbooks.Add(@"c:\MyWork\WorkBook2.xls"); for (int i = 2; i <= app.Workbooks.Count; i++) { int count = app.Workbooks[i].Worksheets.Count

F# Excel Range.Sort Fails or Rearranges Columns

允我心安 提交于 2019-12-20 01:39:57
问题 I have two cases. The preliminary code: open Microsoft.Office.Interop.Excel let xl = ApplicationClass() xl.Workbooks.OpenText(fileName...) let wb = xl.Workbooks.Item(1) let ws = wb.ActiveSheet :?> Worksheet let rows = string ws.UsedRange.Rows.Count First, I try the following to sort: ws.Sort.SortFields.Clear() ws.Sort.SortFields.Add(xl.Range("A8:A" + rows), XlSortOn.xlSortOnValues, XlSortOrder.xlAscending, XlSortDataOption.xlSortNormal) |> ignore ws.Sort.SortFields.Add(xl.Range("H8:H" + rows)

Use Excel Interop to grab image of Excel chart without writing to disk or using the clipboard

此生再无相见时 提交于 2019-12-19 10:25:11
问题 The interface to the chart object in Excel only allows access to the image representing the chart through two methods: export, which saves the image to a file CopyPicture, which saves the image to the clipboard Both of these options are problematic (saving to a file is really slow, and saving to the clipboard could clobber user data). Is there a better way to do this? The only way I can think of is to use to create a temporary ram disk and mount it under say '%TEMP%\tmp_ram_disk\' so that the

Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'. An explicit conversion exists (are you missing a cast?)

 ̄綄美尐妖づ 提交于 2019-12-19 06:05:32
问题 Here I'm opening excel and writing to excel sheet. I'm changing my windows application to asp website and seen this error. I have added all the references and libraries. Don't know what I am missing here. Getting error as mentioned below. Please help me. Excel.Application excel = new Excel.Application(); excel.Visible = false; // to hide the processing Excel.Workbook wb = excel.Workbooks.Add(); Excel.Worksheet sh = wb.Sheets.Add(); // Error at wb sh.Name = "Links"; for (int i = 1; i < list

Passing arrays from VBA to VB.NET

狂风中的少年 提交于 2019-12-19 03:53:11
问题 I am working on a vb.net COM interop to work in Microsoft Excel and I am having trouble passing arrays from vb to vb.net. I have a PointPairs property in the vb.net code that I need to set from vb and I am having trouble passing the 2 dimensional array. I have tried both setting the property explicitly with a 2D array as well as passing two 1D arrays into a Sub to try and set the property in vb.net, but nothing I have tried seems to work. vb.net code: Public Property PointPairs() As Double(,)

Excel process remains open after interop; traditional method not working

冷暖自知 提交于 2019-12-19 02:30:28
问题 I'm running into an issue with some code I'm debugging. Excel interop is used to extract some values from a workbook; however, Excel remains open after the program has exited. I've tried the traditional solution, but it still keeps a reference to Excel open on all machines where the code is run private void TestExcel() { Excel.Application excel = new Excel.Application(); Excel.Workbooks books = excel.Workbooks; Excel.Workbook book = books.Open("C:\\test.xlsm"); book.Close(); books.Close();