Description:-
In this article we will see about how to count last row from excel-sheet. if we want last row from excel for perform any operation like progress-bar, we want to set progress-bar on file upload or insert into table from excel-sheet then we want how may records are inserted or ho many records are reaming then we want last row. or else more operation. here is the code to get last row from excel-sheet.
Code:-
staticvoid getlastrow(Args _args) { SysExcelApplication application,excelApp; SysExcelWorkbooks workbooks,excelWorkBooks; SysExcelWorkbook workbook; SysExcelWorksheets worksheets; SysExcelWorksheet worksheet,excelWorkSheet; SysExcelCells cells,excelCells; COMVariantType type,type1; COM excelCOM; Int lastRow; ; application = SysExcelApplication::construct(); workbooks = application.workbooks(); filename = "<Excel-sheet path>"; try { workbooks.open(filename); } catch (Exception::Error) { throw error("File cannot be opened."); } workbook = workbooks.item(1); worksheets = workbook.worksheets(); worksheet = worksheets.itemFromNum(3); cells = worksheet.cells(); excelCOM = cells.comObject(); excelCOM = excelCOM.SpecialCells(11); // 11 = xlCellTypeLastCell lastRow = excelCOM.Row(); // Row for the last cell info(strFmt("Last rows - %1",lastRow)); application.quit(); }
1 comments:
commentsGreat Job
ReplyThanks for comments.....