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.

rangy.CopyTo and formatting

Thread ID:





80667 Apr 21,2009 10:54 AM Apr 22,2009 08:22 AM Windows Forms 2
Tags: XlsIO
Steve Hookway
Asked On April 21, 2009 10:54 AM

I'm trying to get the same results as IWorksheets.AddCopy (in terms of copy "behavior") with the following code snippet but can't seem to get cell spacing to copy:

for (int i = 0; i < copyCells.Length; i++)

IRange range = copyCells[i];
int col =range.Column;
int row = range.Row;
int lastCol = range.LastColumn;
int lastRow = range.LastRow;
range.CopyTo(sheet.Range[row, col, lastRow, lastCol], ExcelCopyRangeOptions.All);


(just for the motivation - I want to use this approach to copy the same set of ranges over and over (moving down the appropriate number of rows) - to expand a template worksheet)

Steve Hookway
Replied On April 21, 2009 10:59 AM

adding the following lines seem to do the trick:

IRange newRange = sheet.Range[row, col, lastRow, lastCol];
range.CopyTo(newRange, ExcelCopyRangeOptions.All);
newRange.ColumnWidth = range.ColumnWidth;
newRange.RowHeight = range.RowHeight;

I thought ExcelCopyRangeOptions.All would also preserve the spacing. Are there any other values that I should explicitly add to my new range?

Geetha M [Syncfusion]
Replied On April 22, 2009 08:22 AM

Hi Steve,

Excel Range copy method does not copies row / column width / height. The above code copies all the data, formulas, styles and formatting (if any).

Please let me know if you have any questions.



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.