1

I'm using code lines similar to the one below several times throughout the loop. It works all fine EXCEPT it doesn't follow the "no two dot rule", right?

wksheet.Cells(cell.Row, "J").Value

I can store cell.Row as an int, but where to go from there? Is there a function that lets me pass row number and column letter and get the value of that particular cell while still following the rule?

It would be a pain to declare and then set the range variable every time I want to get a particular cell's value inside the loop.

How do I properly clean up Excel interop objects?

^this link explains no two dot rule.

Community
  • 1
  • 1
TPR
  • 2,567
  • 10
  • 41
  • 65
  • 3
    What's the "no two dot rule"? – RB. Jun 29 '12 at 08:33
  • 1
    @RB Trying not to acquire unintended com references that you then can't clean up with Marshal.ReleaseComObject. Alliterated to here http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c-sharp – dash Jun 29 '12 at 08:34
  • I guess this must be it http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c-sharp – Jodrell Jun 29 '12 at 08:35
  • @TPR can you show your loop please? Note that wksheet.Cells(int, int) is a range itself, so you first assign that to a variable, then you take it's value, then you Marshal.ReleaseComObject(range) – dash Jun 29 '12 at 08:37

1 Answers1

2

I guess you could break it down

var row = cell.Row;
var cell = wksheet.Cells(row, "J");
var value = cell.Value;
Jodrell
  • 34,946
  • 5
  • 87
  • 124
  • that's what I mean, it's such a pain to have these two-three lines going around anytime I want to get a simple cell value. I guess I got to do what I got to do. – TPR Jun 29 '12 at 23:03
  • @TPR if you are doing this a lot I guess you could right a function that takes a worksheet, row and column and returns a value. – Jodrell Jul 02 '12 at 08:27
  • That's what I was thinking too. – TPR Jul 02 '12 at 23:03