We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Insert blocks of cells

Hi,

is it possible to insert only a block of cells, like this is possible in Excel? Example:

Excel.Range range1 = worksheet.get_Range(worksheet.Cells[6, 3], worksheet.Cells[15, 5]);
range1.Insert(Excel.XlInsertShiftDirection.xlShiftToRight); // this command inserts a block of 10x3 cells and ONLY shifts the cells located right to "range1" to the right

I only found commands to insert whole rows or columns. The problem here is that inserting a whole column does also move the cells top and bottom to the affected area which in this case is explicitly not wanted. Maybe I have to use some Move()-function?

Thanks in advance & best regards
Christian

1 Reply

AJ Ajish Syncfusion Team July 4, 2007 08:23 PM UTC

Hi Christian ,

Thank you for your interest in Essential XlsIO,

To insert a particular value at a cell range we need to do a rangemove operation to get the desired output and then insert the value. The following method will take a range, Inserted Value as input and shift the cells down.


private void MoveCellsDownAndInsert(IWorksheet sheet, IRange range, string value)
{
int iStartRow = range.LastRow;
int iStartCol = range.Column;
int iLastRow = sheet.UsedRange.End.Row;
int iLastCol = range.LastColumn;

IRange rangeToMove = sheet.Range[iStartRow, iStartCol, iLastRow, iLastCol];
rangeToMove.MoveTo(sheet.Range[range.Row + 1, range.Column]);
range.Value = value;

}

Here is a sample for your reference: http://websamples.syncfusion.com/samples/XlsIO.Windows/F63484/main.htm

Kindly take a look and let us know if this helps.

Regards,
Ajish.

Loader.
Live Chat Icon For mobile
Up arrow icon