Datasheet::SetCell

Description

Set the numeric value of a cell in the worksheet


Set the string value 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

//Put an Image at the given cell (nRow, nCol) in the worksheet. 
#include <image_utils.h>
//#include <..\OriginLab\image_utils.c>
void Datasheet_SetCell_Ex4()
{
    Worksheet wks = Project.ActiveLayer();
    if(!wks)
        return;
    
    FILEINFO fi;
    int nErr;
    string strFilename = "c:\\test.bmp";
    pBITMAPHANDLE pLbmp = image_import(strFilename, &fi, &nErr);
    if(NULL == pLbmp)
    {
        printf("error loading %s, err = %d, abort!\n", strFilename, nErr);
        return;
    }
    
    Image img;
    img.SetLBmp(pLbmp, false);
    wks.SetCell(0, 0, img);
}

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;
}

Remark

See Also

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

header to Include

origin.h