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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

rangy.CopyTo and formatting

Thread ID:

Created:

Updated:

Platform:

Replies:

80667 Apr 21,2009 02:54 PM UTC Apr 22,2009 12:22 PM UTC WinForms 2
loading
Tags: XlsIO
Steve Hookway
Asked On April 21, 2009 02:54 PM UTC

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 02:59 PM UTC

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 12:22 PM UTC

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.

Regards,
Geetha


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.

Warning Icon 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.Close Icon

;