We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copying more than one row with Cells.CopyRows doesn't work for merged cells

In the attached code, I am inserting 3 new rows and copying the 1st row to the row directly after the first row. The first copied row contains merged cells like the source row but the other 2 copied rows do not contain merged cells like they should.

Hi,

Well, I think you misunderstood the last parameter of the CopyRows() method.

public void CopyRows(
Cells sourceCells,
int sourceRowIndex,
int destinationRowIndex,
int rowNumber
);

Parameters

sourceCells
Source Cells object contains data and formattings to copy.
sourceRowIndex
Source row index.
destinationRowIndex
Destination row index.
rowNumber
This refers to number of rows to be copied and related to the the sourceRowIndex parameter.
So, you will always set this parameter to 1 as you are copying the first row over three rows (2nd, 3rd, Fourth).



Please change your code to:

Workbook wb = new Workbook();
wb.Open("Book1.xls");
Worksheet ws = wb.Worksheets[0];
Row row = ws.Cells.Rows[0];
ws.Cells.InsertRows(1, 3);
for (int i = 1; i < 4; i++)
{
ws.Cells.CopyRows(ws.Cells, 0, i, 1);
}

wb.Save("f:\\test\\UpdatedBook1.xls");


Thank you.