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
// 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.
Object objxlWkbk, objxlWorksheet, objxlRange;
// Get the COM object associated with the Excel:
BOOL bOK = wkbk.GetExcelCOMObject(objxlWkbk);
out_str("Failed to get the COM object!");
// 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.
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);