Mathias Brandewinder on .NET, VSTO and Excel development, and quantitative analysis.
by Mathias 6. January 2009 19:05

I am currently working on an application which requires reading the contents of an Excel worksheet into a 2-dimensional array. I want to avoid loading the entire contents of the worksheet, and want to read only the upper-left quadrant, and leave out all the empty cells on the left and the bottom of the sheet. Problem is, how do you find out the last cell that contains something, that is, the cell such that no cell below it or on its right has content?

Everything Google turned up looked pretty nasty - either brute force, or acrobatic usage of Excel functions, until I stumbled across this little gem:

var lastCell = xlWorksheet.Cells.SpecialCells(
    Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, 
    Type.Missing);

You learn everyday.

Comments

10/8/2009 4:46:23 PM #

trackback

Read the contents of a worksheet with C#

Read the contents of a worksheet with C#

Clear Lines Blog | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Comments

Comment RSS