Skip to content

Instantly share code, notes, and snippets.

@Oblongmana
Last active December 16, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oblongmana/5478795 to your computer and use it in GitHub Desktop.
Save Oblongmana/5478795 to your computer and use it in GitHub Desktop.
This contains #Extension methods for #Excel objects. At present, just contains a method for simplifying getting the #Value2 for a particular column/row in a particular worksheet. This gives the value back, and takes care of the COM management stuff nicely, so you can just call worksheetInstance.GetCellValue2(colInt,rowInt) without thinking too h…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using MyExtensions
namespace MyExtensions
{
public static class ExcelExtensions
{
public static dynamic GetCellValue2(this Excel._Worksheet theWorksheet, int column, int row) //lolwut:static dynamic
{
Excel.Range theRange = (Excel.Range)theWorksheet.Cells[row, column];
dynamic theValue = theRange.Value2;
theRange.CloseReleaseAndNullComObject();
return theValue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment