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

Free Support Forum - aspose.com

Copy Row to another Row

Hi

I have the following code to copy one row data to another rows

Workbook workbook = new Workbook(@"C:\Documents and Settings\amj001\Desktop\ExampleSheet.xlsx");

//Open an existing excel file

Worksheet worksheet = workbook.Worksheets[0];

//Get the first worksheet cells

Cells cells = worksheet.Cells;

//Copy the first row to next 10 rows

cells.CopyRows(cells, 0, 1, 10);

//Save the excel file

workbook.CalculateFormula();

workbook.Save(@"C:\Documents and Settings\amj001\Desktop\ExampleSheetOutPut.xlsx");

Using this code i tried to copy first row data to next 10 rows ,but in my output it copied only one row not 10 that is first row copied only to next row ,not next 10 rows

what wrong am doing here

Hi,


You need to change your code a bit accordingly, see the updated code segment:


//Open an existing excel file

Worksheet worksheet = workbook.Worksheets[0];

//Get the first worksheet cells

Cells cells = worksheet.Cells;

//Copy the first row to next 10 rows

int numberOfTimes = 10;
for (int i = 1; i <= numberOfTimes; i++)
{
worksheet.Cells.CopyRows(cells, 0, i, 1);
}

//Save the excel file

workbook.CalculateFormula();