Get range address in Excel using vb.net -


i trying dynamically range of cells in excel using vs 2005 vb.net. works orange = osheet.range(osheet.cells("a1"), ("u281")).select, "u281" not last cell in range. how dynamically last cell data in same format u281.

to last cell, use formula:

lastcell = osheet.cells.specialcells(xlcelltype.xlcelltypelastcell) 

this works fine, unless have users have been strange areas of spreadsheet , done things have since deleted. above formula return last cell being wherever went on strange journeys, if blank.

in case, have process every cell in lot of spreadsheets user went down row 60,741 , column 50 though there couple of hundred lines of actual data. avoid massive blank region, want search maximum row , maximum column have data , use cell bottom right corner of square of cells has data, below (it's c# shouldn't hard translate):

microsoft.office.interop.excel.range maxcell =      (microsoft.office.interop.excel.range)worksheet.cells[worksheet.cells.find("*",     (microsoft.office.interop.excel.range)worksheet.cells[1, 1],     microsoft.office.interop.excel.xlfindlookin.xlvalues,     microsoft.office.interop.excel.xllookat.xlwhole,     microsoft.office.interop.excel.xlsearchorder.xlbyrows,     microsoft.office.interop.excel.xlsearchdirection.xlprevious,      false, false, missing).row,     worksheet.cells.find("*",      (microsoft.office.interop.excel.range)worksheet.cells[1, 1],      microsoft.office.interop.excel.xlfindlookin.xlvalues,     microsoft.office.interop.excel.xllookat.xlwhole,      microsoft.office.interop.excel.xlsearchorder.xlbycolumns,     microsoft.office.interop.excel.xlsearchdirection.xlprevious,      false, false, missing).column]; 

this can save lot of processing time.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -