/*------------------------------------------------------------------------------* * File Name: GetWorksheetSelection.c * * Creation: ER, 01/24/05 * * Purpose: Programming Example * * Copyright (c) OriginLab Corp.2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #include ///////////////////////////////////////////////////////////////////////////////// // This example shows how to get the range of cells that a user has selected // on the active worksheet. // Have a worksheet window active, make a range selection on the worksheet, // and then call this function // void get_worksheet_selection() { // Declare worksheet object with active layer Worksheet wks = Project.ActiveLayer(); if( !wks ) { out_str("Active layer is not a worksheet!"); return; } int c1, c2, r1, r2; // Get worksheet selection int nSelType = wks.GetSelection(c1, c2, r1, r2); // If nothing was selected, return if( WKS_SEL_NONE == nSelType ) { out_str("Nothing was selected in the worksheet!"); return; } // Report selection printf("Selection: Row %d, Col %d to Row %d, Col %d\n", r1 + 1, c1 + 1, r2 + 1, c2 + 1); // Note: 1 was added to r1, c1 etc because Origin C uses 0-based offset and in the // GUI typically the count starts at 1. // One can then perform further processing on the selection // such as, for example: // Get the selected cells into a matrix object matrix mat; BOOL bRet = mat.CopyFrom(wks, r1, c1, r2, c2); // Report min, max, mean, and median printf("Min, max, mean and median of selection: %f, %f, %f, %f\n", mat.GetMin(), mat.GetMax(), mat.GetMean(), mat.GetMedian()); } /////////////////////////////////////////////////////////////////////////////////