Copy data to worksheet with optional row shift
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 )
If the method succeeds, the return value is zero else a nonzero error value is returned.
// 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); } }
origin.h