I need to “shift” several cells within one column a few rows down but leave the rest of these rows intact. The cells have named ranges and formatting.
I only found CopyRow and CopyColumn methods but nothing to copy individual cells or ranges.
Mike
Hi Mike,
Thanks for considering Aspose.
Well you may try to use Range.Copy() method of copy a complete range of cells with formattings. I write the following sample code for you, May the following code provide help for your need:
Workbook workbook = new Workbook();
Worksheets worksheets = workbook.Worksheets;
Worksheet worksheet = workbook.Worksheets[0];
// Create a range of cells in a column
Range range1 = worksheet.Cells.CreateRange("E50","E60");
range1.Name = "MyRange";
// Create a style object
Style stl;
stl= worksheet.Cells.Rows[0].Style;
stl.Font.Name = "Tahoma";
stl.Font.IsBold = true;
// Set the font text color
stl.Font.Color = Color.Red;
// To Set the fillment color of the range, you will use ForegroundColor
// and set Pattern to solid.
stl.ForegroundColor = Color.Yellow;
stl.Pattern = BackgroundType.Solid;
// Set Text into the first cell of the range.
range1[0,0].PutValue("Testing");
// Set Text into the last cell of the range.
range1[10,0].PutValue("123");
// Set the style to the range
range1.Style = stl;
// Now access the existing range above.
Range range2 = worksheet.Cells.CreateRange("B1","B11");
range2.Name = "testrange";
range2.Copy(range1);
workbook.Save("d:\\test\\testrangecopy.xls");
And If you want to copy a cell's data you may use Cell.Copy() method.
Thank you.