Datasheet::SetCell

Description

Set the numeric value of a cell in the worksheet


Set the string (including supported link) of a cell in the worksheet


Put a copy of the XML tree into a cell


Put an Image at the given cell (nRow, nCol) in the worksheet

Syntax

BOOL SetCell( int nRow, int nCol, double value )

BOOL SetCell( int nRow, int nCol, LPCSTR lpcszText, BOOL bConsiderNumeric = true )

BOOL SetCell( int nRow, int nCol, LPCSTR lpcszName, const TreeNode & tr )

BOOL SetCell( int nRow, int nCol, Image & img, DWORD dwAttachInfo = 0 )

Parameters

nRow
[input] Row number with zero offset
nCol
[input] Column number with zero offset
value
[input] Value to set at the location (nRow, nCol)

nRow
[input] Row number with zero offset
nCol
[input] Column number with zero offset
lpcszText
[input] String to set location (nRow, nCol)
bConsiderNumeric
[input] when true, check lpcszText and set as numeric including "--" to become numeric missing value

nRow
[input] Row number with zero offset
nCol
[input] Column number with zero offset
lpcszName
[input] A name must be given to be associated with the XML tree, as the data is actually stored in the Column info area
tr
[input] Tree to be copied, a deep copy is performed

nRow
[input] Row number with zero offset
nCol
[input] Column number with zero offset
img
[input] Image to to put into the cell
dwAttachInfo
[input] Define attach parameters, can be one or more of the following
EMBEDGRAPH_KEEP_ASPECT_RATIO = 0x00000010, // Keep Aspect Ratio
EMBEDGRAPH_IN_LABELS = 0x00000020, // Embeds the graph in Label
EMBEDGRAPH_DO_UNDO = 0x00000040, /// Allows undo of the attachment

Return

TRUE for success; otherwise FALSE.


TRUE for success; otherwise FALSE.


TRUE for success; otherwise FALSE.


TRUE for success; otherwise FALSE.

Examples

EX1

//Set the numeric value of a cell in the worksheet.
int Datasheet_SetCell_Ex1()
{
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return -1;
    
    Worksheet wks(wp.GetName());
    double value = 1000.05;
    int iResult;
    iResult = (int)wks.SetCell(0, 0, value);
    double cellValue = wks.Cell(0, 0);
    printf("Value at (0,0) location is %f\n", cellValue);
    return iResult;
}


EX2

//Set the string value of a cell in the worksheet 
int Datasheet_SetCell_Ex2()
{
    WorksheetPage wp = Project.WorksheetPages(0);
    if(!wp)
        return -1;
    
    Worksheet wks(wp.GetName());
    string strText = "Monday";
    int iResult;
    string cellText;

    iResult = (int)wks.SetCell(0, 0, strText);
    wks.GetCell(0, 0, cellText);
    printf("Value at (0,0) location is %s\n", cellText);
    return iResult;
}


EX3

//put a copy of the XML tree into a cell 
int Datasheet_SetCell_Ex3()
{
    Tree tr1;
    TreeNode tr = tr1.AddNode("Test");
    tr.AA.strVal = "Some text";
    tr.BB.dVals = 0.1234;

    Worksheet wks = Project.ActiveLayer();
    int nR = 1;
    int nC = 1;
    string strName = "Pear Tree";

    return (int)wks.SetCell(nR, nC, strName, tr1.Test);
}


EX4

//Insert image as link to 1st cell of 1st column in worksheet
void linkimg(int nr = 0, string strFile = "bamboo.jpg")
{
        string path = GetOriginPath() + "Samples\\Image Processing and Analysis\\";
        path += strFile;
        Worksheet wks = Project.ActiveLayer();
        wks.SetCell(nr, 0, "file://" + path);
}

Ex5

//Set the numeric value of a cell in the matrix.
void Datasheet_SetCell_Ex5()
{
        MatrixLayer ml = Project.ActiveLayer();
        if ( !ml )
        {
                printf("Can not access active matrixsheet");
                return;
        }
        ml.SetCell(0, 0, 3333); //set the active matrixobject's first cell value;
        return;
}

EX6

//New in Origin 2023
//Add a clickable link to an image file in cell. Click it will open the image
void linkimg(int nr = 0, string strLabel = "Click Me", string strFile = "bamboo.jpg")
{
        string path = GetOriginPath() + "Samples\\Image Processing and Analysis\\";
        path += strFile;
        Worksheet wks = Project.ActiveLayer();
        //file path must be quoted in case there are spaces
        string str = "path://\"";
        str += path;
        str += "\" ";
        str += strLabel;
        wks.SetCell(nr, 0, str);
}

Remark

See Also

Datasheet::Cell,Datasheet::TCell,Worksheet::GetCell,Worksheet::AttachPicture

header to Include

origin.h