Copies a specified range from a worksheet to a matrix.
BOOL CopyFromWks( Worksheet & wksSource, int c1 = 0, int c2 = -1, int r1 = 0, int r2 = -1, DWORD dwCntrl = 0 )
Returns TRUE on successful exit and FALSE on failure.
EX1
// Copy partial worksheet data into a matrix void matrixbase_CopyFromWks_ex1() { BOOL rc; Worksheet wks; wks.Create(); Dataset myXDs(wks,0); Dataset myYDs(wks,1); String wksName=wks.GetPage().GetName(); //******* Create sample data ***************** myXDs.SetSize(4); myYDs.SetSize(4); myXDs[0]=0; myYDs[0]=0.5; myXDs[1]=1; myYDs[1]=1.5; myXDs[2]=2; myYDs[2]=2.5; myXDs[3]=3; myYDs[3]=3.5; matrix<double> mat1 = { {0, 0, 0, 0}, {0, 0, 0, 0} }; //******** End of Sample Data Creation ******* MatrixPage MatPg1; MatPg1.Create("Origin"); MatrixLayer MatLy1 = MatPg1.Layers(0); Matrix Mat1(MatLy1); Mat1 = mat1; printf(" The original matrix is %s(Size=%dx%d).\n", Mat1.GetName(),Mat1.GetNumRows(),Mat1.GetNumCols()); MatrixPage MatPg2; MatPg2.Create("Origin"); MatrixLayer MatLy2 = MatPg2.Layers(0); Matrix Mat2(MatLy2); rc = mat1.CopyFromWks(wks); //Copies the whole wks to mat1 Mat2 = mat1; if(!rc) printf(" Error: CopyFromWks failed.\n"); else printf(" %s has been copied into %s(Size=%dx%d).\n", wksName,Mat2.GetName(),Mat2.GetNumRows(),Mat2.GetNumCols()); // Result matrix by this sample program will be: // {0, 0.5} // {1, 1.5} // {2, 2.5} // {3, 3.5} MatrixPage MatPg3; MatPg3.Create("Origin"); MatrixLayer MatLy3 = MatPg3.Layers(0); Matrix Mat3(MatLy3); rc = mat1.CopyFromWks(wks,1,1,2,3); //Copies a part of wks to mat1 Mat3 = mat1; if(!rc) printf(" Error: CopyFromWks failed.\n"); else printf(" %s has been copied into %s(Size=%dx%d).\n", wksName,Mat3.GetName(),Mat3.GetNumRows(),Mat3.GetNumCols()); // Result matrix: // {2.5} // {3.5} }
Copies a specified range from a worksheet to a matrix dynamically resizing the matrix as needed.
origin.h