2.2.4.46.8 Worksheet::CopyToCopyTo
Description
Copy data to worksheet with optional row shift
Syntax
int CopyTo( Worksheet & wksDest, int nC1, int nC2, int nR1, int nR2, int nDestC1, int nLNRow = -1, DWORD dwCntrl
= CPYT_EXTERN_UPDATE_ORIGIN, int nDestR1 = 0, vector<int>* pvnLabelTypes = NULL )
Parameters
- wksDest
- [modified] output worksheet, created if not attached to existing
- nC1
- [input] source(this) starting column to copy, 0 offset
- nC2
- [input] ending column to copy, -1 to copy all columns (Inclusive)
- nR1
- [input] beginning data row, 0 offset
- nR2
- [input] ending data row, -1 to last row (Exclusive)
- nDestC1
- [input] output worksheet first column index, 0 offset
- nLNRow
- [input] source worksheet row index to use as output column long names, -1 if not applicable
- dwCntrl
- [input] specify which properties of column to be copied
- see CPYTOPTION in oc_const.h, Can be:
- CPYT_COPY_COLUMN_FORMAT,
- CPYT_COPY_COLUMN_DESIGNATIONS,
- CPYT_COPY_COLUMN_LABELS,
- CPYT_COPY_ATTACHED_EMF,
- ...
- nDestR1
- [input] output sheet first row index, 0 offset (8.1SR0)
- pvnLabelTypes
- [input] Specify which kind of labels should be copied, NULL means all shown labels should be copied. For this control to be effect, CPYT_COPY_COLUMN_LABELS in dwCntrl should be turned on. (8.1SR1)
- see ROWCOLLABELTYPE in oc_const.h, Can be:
- RCLT_LONG_NAME,
- RCLT_UNIT,
- RCLT_COMMENT,
- RCLT_UDL ( RCLT_UDL + 1, RCLT_UDL + 2 stands for the 2rd, 3th user defined parameter ),
- ...
Return
If the method succeeds, the return value is zero else a nonzero error value is returned.
Examples
// This example will copy columns with specified column labels into a new worksheet.
// Before running this example please activate a worksheet that contains data and has longname and unit cells filled.
void Worksheet_CopyTo_Ex1()
{
// Use the active worksheet as our data source
Worksheet wksSource = Project.ActiveLayer();
if( wksSource )
{
// Create a new worksheet to be the target of our copy
Worksheet wksTarget;
wksTarget.Create("origin");
// Copy from all columns
// Remember that column and row indexes are zero based
int nC1 = 0, nC2 = -1; // Use -1 to indicate last column
// Copy the first 9 rows
// The source ending row (nR2) is exclusive
int nR1 = 0, nR2 = 9;
// Copy to the target worksheet starting at the 2nd column
// Remember that column indexes are zero based
int nDestC1 = 1;
// Also copy column formats, designations and column labels.
DWORD dwCtrl = CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS | CPYT_COPY_COLUMN_LABELS;
// Define a vector specifying longname and unit to be copied.
vector<int> vnLabelTypes;
DWORD dwLabel = RCLT_LONG_NAME;
vnLabelTypes.Add(dwLabel);
dwLabel = RCLT_UNIT;
vnLabelTypes.Add(dwLabel);
int nRet = wksSource.CopyTo(wksTarget, nC1, nC2, nR1, nR2, nDestC1, -1, dwCtrl, 0, &vnLabelTypes);
}
}
// Before running this example please activate a worksheet that contains data.
void Worksheet_CopyTo_Ex2()
{
Worksheet wksSource = Project.ActiveLayer();
if( wksSource )
{
// Copy from all columns
int nC1 = 0, nC2 = -1;
// The source ending row (nR2) is exclusive
int nR1 = 2, nR2 = 4;
//Copy to the worksheet starting at the 12th column
int nDestR1 = 12;
DWORD dwCtrl = CPYT_APPEND_BY_ROW | CPYT_ALLOW_SAME_LAYER_IF_NOT_INTERSECT;
int nRet = wksSource.CopyTo(wksSource, nC1, nC2, nR1, nR2, 0, -1, dwCtrl, nDestR1);
}
}
Remark
See Also
Worksheet::CreateCopy
Header to Include
origin.h
|