3.4.8 Graph Add Wks Table
Version Info
Minimum Origin Version Required: Origin 8 SR0
Need to do before Running Examples
Prior to running the following example, the graph_utils.c file need to be loaded and compiled. This can be done from script with the following command or just add this file to your workspace.
run.LoadOC(Originlab\graph_utils.c);
Example
#include <..\Originlab\graph_utils.h>
void graph_add_table()
{
GraphPage gp;
gp.Create("Origin");
GraphLayer gl = gp.Layers(); // get active layer
// 1. create table worksheet
Worksheet wks;
wks.Create("Table", CREATE_HIDDEN); // create hidden worksheet with "Table" template
WorksheetPage wp = wks.GetPage();
wp.Rename("Table1");
// 2. set table size and fill in text; add table as link to graph
wks.SetSize(3, 2);
wks.SetCell(0, 0, "1");
wks.SetCell(0, 1, "Layer 1");
wks.SetCell(1, 0, "2");
wks.SetCell(1, 1, "Layer 2");
wks.SetCell(2, 0, "3");
wks.SetCell(2, 1, "Layer 3");
GraphObject grTable = gl.CreateLinkTable(wp.GetName(), wks);
// 3. arrange size and position of table
// get the position of graph layer
int Unit;
double dLeft, dTop, dRight, dBottom;
layer_get_position(gl, &dLeft, &dTop, &dRight, &dBottom, &Unit);
// convert unit to Inch
vector xx(4);
xx[0] = dRight - dLeft; //width
xx[1] = dBottom - dTop; //height
xx[2] = dLeft;
xx[3] = dTop;
gl.UnitsConvert(M_INCH, xx, Unit);// convert value in xx to Inch unit
// change Left and Top according to layer 3
double grLeft = xx[2] + 0.1; // left of layer 3 + 0.1 Gap
double grTop = xx[3]; // top of layer 3
Tree tr;
tr.Root.Dimension.Left.dVal = grLeft;
tr.Root.Dimension.Top.dVal = grTop;
tr.Root.Dimension.Units.nVal = 0; // 0: inch
if( 0 == grTable.UpdateThemeIDs(tr.Root) )
grTable.ApplyFormat(tr.Root, true, true);
}
|