excel-interop

excel interop alternative

落花浮王杯 提交于 2019-12-03 06:57:51
I have started using the Excel interop assemblies that are provided by Microsoft for one of my C# applications. Everything is going fine, but there seems to be a lack of strong typing, and honestly it feels like I am writing VBA code. Are there any alternative ways to interact with Excel from C# that would give a better OO experience? I am using VS2010 and .Net 4.0 by the way. Take a look at the EPPlus project over at Codeplex: http://epplus.codeplex.com/ I recently used this and it worked very well. (VS2010 and .Net4) EPPlus is a .net library that reads and writes Excel 2007/2010 files using

Adding hyperlinks in Excel[2007] in C# - Within Excel it self

雨燕双飞 提交于 2019-12-03 06:15:10
Can anybody tell me how we can add a hyperlink in Excel (2007 or later) from a cell in one sheet to a cell in another sheet using Office Interop in .NET (c#) For example: A hyperlink from Sheet1 Cell A1 to Sheet2 Cell B10 What you want to use here is the Hyperlinks.Add method. You can call it with code that looks something like this: Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1]; Excel.Range rangeToHoldHyperlink = worksheet.get_Range("A1", Type.Missing); string hyperlinkTargetAddress = "Sheet2!A1"; worksheet.Hyperlinks.Add( rangeToHoldHyperlink, string.Empty,

Changing an Excel cell's backcolor using hex results in Excel displaying completely different color in the spreadsheet

↘锁芯ラ 提交于 2019-12-03 06:03:15
So I am setting an Excel cell's Interior Color to a certain value, like below: worksheet.Cells[1, 1].Interior.Color = 0xF1DCDB; However, when I then open up the spreadsheet in Excel, I see that the color that came out is completely different (in the above case, the color in the resulting spreadsheet is 0xDCDCEF). I tried a few different colors and it always changes it, and I don't see a pattern. Is there any reason for this? I even tried setting the color by writing Color.FromArgb(241, 220, 219).ToArgb(), and the same thing happened. I finally figured it out, after lots of tests, and it was

Why is Excel changing my date display value, and how can I prevent it from doing that?

蓝咒 提交于 2019-12-02 13:03:44
问题 It seems that Excel is taking values I assign to cells, such as "Sep 15" and changing them to "15-Sep" I have code that should assign the val in the format I want ( MMM yy ): internal static string GetMMMYYFromYYYYMM(String YYYYMMVal) { // code from http://stackoverflow.com/questions/40045761/how-can-i-convert-a-string-in-the-format-yyyymm-to-mmmyy DateTime intermediateDate = DateTime.ParseExact(YYYYMMVal, "yyyyMM", CultureInfo.InvariantCulture); return intermediateDate.ToString("MMM yy"); }

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

旧时模样 提交于 2019-12-02 11:43:38
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.Multiselect = true; DialogResult result = browse.ShowDialog(); if (result == DialogResult.OK) try /

Get Cell Value in Excel from Range

删除回忆录丶 提交于 2019-12-02 11:33:29
How can I extract the value of a cell from a range object? It seems like it should be simple. This Stackoverflow question and answers did not really help. Here is what I want to do but it fails every time with an exception on row.columns(0,0). Dim rdr = oFindings.Range For Each row As Excel.Range In rdr.Rows Dim Account = row.Columns(0,0).value2.tostring ' Do other stuff Next To make it work I had to implement this code: For Each row As Excel.Range In rdr.Rows ndx = 0 For Each cell As Excel.Range In row.Columns If ndx = 0 Then Account = NS(cell.Value2) ' Do other stuff ndx += 1 next Next That

How to hide publishing progress bar for ExportAsFixedFormat

六眼飞鱼酱① 提交于 2019-12-02 10:02:34
问题 I am trying to convert Excel file to PDF using interop.excel , while executing ExportAsFixedFormat 'publishing' progress bar displays on the site. Is there any way to hide this? I found this issue for Excel files having size above 300KB. Code is given below: //(tried using Application instead of ApplicationClass) Microsoft.Office.Interop.Excel.ApplicationClass excelApplication = new Microsoft.Office.Interop.Excel.ApplicationClass(); excelApplication.ScreenUpdating = false; excelApplication

Is there a “sister” function to “AutoFilter” in Excel Interop that works for columns instead of rows?

◇◆丶佛笑我妖孽 提交于 2019-12-02 09:43:48
The "AutoFilter" function in Excel Interop allows you to filter what data in the rows beneath a column display. I need a similar function to allow the user to select which columns to hide. For example and specifically, if there is a set of columns 3..15 (C..0) going from "Sep 15" to "Sep 16" with the obvious months in between them ("Oct 15", etc.) I want the user to be able to select any subset of those columns to view. Those deselected would "disappear" How can this be accomplished? I have tried the following, but the second filter has no effect: private void AddFilters() { Range column1Row6

Basic of XLL Excel Addin - Need to invoke a C# API from Excel [closed]

安稳与你 提交于 2019-12-02 08:41:38
I am quite new to creating excel addins. Earlier I used to create a tlb for .NET libraries. I used to make my .NET class COMVISIBLE and create a Com callable wrapper and register as a tlb to call from Excel (using regasm). I now have a math library written in C#. Got to know there is something called XLL and UDFs which I can use to invoke API's from the DLL. Little confused about XLA, XLL and UDFs. Not sure what should I do to call my API's. Not sure where to get started. Any help would be helpful. Thanks Mani Take a look at XLDNA , XLL+ , Addin Express , VSTO etc. Don't forget to take a look

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 06:58:43
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 Week { get; set; } public String Price { get; set; } public String Variance { get; set; } public String