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
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 )
TRUE for success; otherwise FALSE.
TRUE for success; otherwise FALSE.
TRUE for success; otherwise FALSE.
TRUE for success; otherwise FALSE.
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); }
Datasheet::Cell,Datasheet::TCell,Worksheet::GetCell,Worksheet::AttachPicture
origin.h