Hi,
You can use the CopyTo method. Here is the example:
void copy_selected_rows()
{
WorksheetPage wp = Project.WorksheetPages(0); // workbook
if(!wp)
return;
Worksheet wks = wp.Layers(0); // first worksheet in workbook
if(!wks)
return;
vector<int> vR1; // the rows to be selected
vR1.Add(5); // indices of some rows to be selected
vR1.Add(8);
vR1.Add(14);
vR1.Add(23);
wks.SetSelectedRange(vR1); // highlight the rows
string strNew = "NewWks";
int nn = wp.AddLayer(strNew); // add a worksheet to workbook
Worksheet wks2 = wp.Layers(nn); // get the newly added worksheet
if(!wks2)
return;
wks2.SetSize(vR1.GetSize(), wks.GetNumCols()); // set size of the new worksheet
for(int ii = 0; ii < vR1.GetSize(); ii++) // loop to copy the selected rows to the new worksheet
{
wks.CopyTo(wks2, 0, -1, vR1[ii], vR1[ii] + 1, 0, -1, CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS, ii);
}
}
Penn