I think the question sums it up. Given two integers for row and column or four integers for row and column for the two corners of a range, how do I get a range object for th
Try this, works!
Excel.Worksheet sheet = xlWorkSheet;
Excel.Series series1 = seriesCollection.NewSeries();
Excel.Range rng = (Excel.Range)xlWorkSheet.Range[xlWorkSheet.Cells[3, 13], xlWorkSheet.Cells[pp, 13]].Cells;
series1.Values = rng;
you can retrieve value like this
string str = (string)(range.Cells[row, col] as Excel.Range).Value2 ;
select entire used range
Excel.Range range = xlWorkSheet.UsedRange;
source :
http://csharp.net-informations.com/excel/csharp-read-excel.htm
flaming
UsedRange work fine with "virgins" cells, but if your cells are filled in the past, then UsedRange will deliver to you the old value.
For example:
"Think in a Excel sheet that have cells A1 to A5 filled with text". In this scenario, UsedRange must be implemented as:
Long SheetRows;
SheetRows = ActiveSheet.UsedRange.Rows.Count;
A watch to SheetRows variable must display a value of 5 after the execution of this couple of lines.
Q1: But, what happen if the value of A5 is deleted?
A1: The value of SheetRows would be 5
Q2: Why this?
A2: Because MSDN define UsedRange property as:
Gets a Microsoft.Office.Interop.Excel.Range object that represents all the cells that have contained a value at any time.
So, the question is: Exist some/any workaround for this behavior?
I think in 2 alternatives:
Long SheetRows;
SheetRows = ActiveSheet.Range("A1").CurrentRegion.Rows.Count;