First thing we need to take reference of below namespace:
using Excel = Microsoft.Office.Interop.Excel;
Classes used :
MyApp = new Excel.Application();
MyApp.Visible = false; // Run Excel in background.
MyBook = MyApp.Workbooks.Open(DB_PATH);
MySheet = (Excel.Worksheet)MyBook.Sheets[1];
// Explicit cast is not required here
lastRow = MySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
MySheet .Cells[1, 2] = "Percentage(%)"; // Here 1 is the rowIndex and 2 is the columnIndex
// Reading rows from used row.
using Excel = Microsoft.Office.Interop.Excel;
Classes used :
Excel.Application-Top level object in the Excel object model, used to specify application level properties and application level methodsExcel.Worbook- Represents a single workbook within the Excel applicationExcel.Worksheet- A member of theWorksheetscollection in theWorkbookobject
MyApp = new Excel.Application();
MyApp.Visible = false; // Run Excel in background.
MyBook = MyApp.Workbooks.Open(DB_PATH);
MySheet = (Excel.Worksheet)MyBook.Sheets[1];
// Explicit cast is not required here
lastRow = MySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
MySheet .Cells[1, 2] = "Percentage(%)"; // Here 1 is the rowIndex and 2 is the columnIndex
// Reading rows from used row.
//I presume you are actually looking for the last used row. In that case you need to write like this:
|
No comments:
Post a Comment