Thursday, 8 January 2015

Remove Rows and Columns from existing Excel sheet using asp.net c#

    
using System;
using System.Collections.Generic;
using System.Text;
using Excel1 = Microsoft.Office.Interop.Excel;

namespace Removing_rows_from_existing_XLS
{ object misValue = System.Reflection.Missing.Value;
        Excel1.Application xlApp;
        Excel1.Workbook xlWorkBook;
        Excel1.Worksheet xlWorkSheet;
        xlApp = new Excel1.Application();
        xlWorkBook = xlApp.Workbooks.Add(1);
        xlWorkSheet = (Excel1.Worksheet)xlWorkBook.Worksheets.get_Item(1);

Excel1.Range ChartRange;
 ChartRange = xlWorkSheet.get_Range((object)xlWorkSheet.Cells[1, First cell], (object)xlWorkSheet.Cells[5, Last cell]);


//Delete rows
xlWorkSheet.Range[Startrows cell, End rows cell]. Rows .Delete(misValue);

//or
xlWorkSheet. ChartRange .Rows .Delete(misValue);


//Delete Columns
xlWorkSheet.Range[Startrows cell, End rows cell]. Cell.Delete(misValue);

//or
xlWorkSheet. ChartRange .Cell.Delete(misValue);
}

//Result









No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...