GetAs2DArray
Get the contents of the vector as a variant holding a 2D array.
_VARIANT GetAs2DArray( int numColumns, BOOL bArrayOfVariants = TRUE )
the 2D array with the contents of the vector
EX1
// For this example to run, have an Excel workbook inside Origin with the name "Book2", // and put some data into it. For example, click Import Simple ASCII toolbar button // to import Multiple Gaussians.dat file from Origin Samples\Curve Fitting folder. // The example will get a block data of the specified subrange from Excel window, // multiply 10 on the value of each cell and then put back data to Excel. void vectorbase_GetAs2DArray_ex1() { WorksheetPage wkbk("Book2"); if (!wkbk) { out_str("Invalid WorksheetPage!"); return; } Object objxlWkbk, objxlWorksheet, objxlRange; // Get the COM object associated with the Excel: BOOL bOK = wkbk.GetExcelCOMObject(objxlWkbk); if (!bOK) { out_str("Failed to get the COM object!"); return; } // The active sheet: objxlWorksheet = objxlWkbk.ActiveSheet; // The Range object: objxlRange = objxlWorksheet.Range("$B$2:$D$12"); // Get the values from the Range as a vector // Note the data type of the following vector is double since the data type in the current Excel is double. // Please use the correct data type for vector according to the data's type in Excel. vector<double> vec; vec = objxlRange.Value; // Loop to string-reverse the contents of each element: for (int ii = 0; ii < vec.GetSize(); ii++) { vec[ii] = vec[ii] * 10; } // Put the values back into Excel (3 is the number of columns in the "$B$2:$D$12" range; note // that Excel requires that the data be set into a Range object as a two-dimensional array): objxlRange.Value = vec.GetAs2DArray(3); }
vectorbase::GetAs1DArray
origin.h