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

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...