Hi,
Please refer to the example below:
void SumUp_Worksheets()
{
WorksheetPage wksPage("Book1"); // Workbook
if(!wksPage)
return;
foreach(Layer layer in wksPage.Layers) // All worksheets in workbook
{
Worksheet wks(layer);
DataRange dr; // Data range to the whole worksheet
dr.Add(wks, 0, "X", -1);
matrix mData;
dr.GetData(mData); // Get worksheet data into matrix
int nRows = mData.GetNumRows(); // number of rows
int nCols = mData.GetNumCols(); // number of columns
vector vSum(nRows); // vector to strore sum of rows in each worksheet
// Sum up each rows in all columns
int nRet = ocmath_row_desc_stats(nRows, nCols, mData, NULL, NULL, NULL, NULL, NULL, vSum);
int nn = wks.AddCol(); // Add a column to store these sums
Column col(wks, nn);
col.SetLongName("Sum of Rows");
vectorbase& vv = col.GetDataObject();
vv = vSum;
// Sum up each columns in worksheet
for(int ii = 0; ii < nCols; ii++)
{
Column colSrc(wks, ii);
vectorbase& vSrc = colSrc.GetDataObject();
double dSum;
vSrc.Sum(dSum);
nn = wks.AddCol(); // Add a column to hold the sum in the first cell
wks.Columns(nn).SetLongName("Sum of Column "+colSrc.GetName());
wks.SetCell(0, nn, dSum);
}
// Sum up the whole worksheet
double dWksSum;
nn = wks.AddCol(); // Add a column to hold the sum of worksheet in the first cell
wks.Columns(nn).SetLongName("Sum of All Values in Sheet");
vv.Sum(dWksSum);
wks.SetCell(0, nn, dWksSum);
}
}
Penn