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.
Unfortunately, activation email could not send to your email. Please try again.

Insert blocks of cells

Thread ID:

Created:

Updated:

Platform:

Replies:

63484 Jul 4,2007 12:25 PM Jul 4,2007 04:23 PM Windows Forms 1
loading
Tags: XlsIO
Christian Nein
Asked On July 4, 2007 12:25 PM

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

Ajish [Syncfusion]
Replied On July 4, 2007 04:23 PM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;