Get subrange of range

时间:2018-12-03 12:49:48

标签: c# excel-interop

How can get a subrange from the range?

For example, get 100 rows from usedrange?

using Excel = Microsoft.Office.Interop.Excel;
//
Excel.Worksheet excelSheet = File.Worksheets["Sheetname"];
Excel.Range subrange = excelSheet.UsedRange.Range["1:100"];

I've tried the code above with file with UsedRange "A1:AM550". I expect that excelSheet.UsedRange.Range["1:100"] will return first 100 rows from UsedRange. But the code above returns me a range of excelSheet.Range["1:100"], with all the columns!

Is it an appropriate way to get the range from the range (without taking UsedRange into object[,] or DataTable, cause UsedRange can be too big for that).

Thanks

0 个答案:

没有答案