3.2.4 Worksheet Access Embedded Graphs
Version Info
Minimum Origin Version Required: Origin 8 SR0
List Embedded Graphs
List all embedded graph pages in the active workbook, along with embedding information(Worksheet, Row, Column).
void get_embedded_graphs()
{
WorksheetPage wpg = Project.Pages();
if( wpg )
{
foreach(Layer ly in wpg.Layers)
{
Worksheet wks = ly;
foreach(Page pgEmbedded in wks.EmbeddedPages)
{
Worksheet wksTest;
int nRow, nCol;
bool bRet = pgEmbedded.GetEmbeddingInfo(wksTest, &nRow, &nCol);
// TRUE if the object is embedded in a Datasheet, otherwise FALSE.
if( bRet )
{
printf("%s in [%s]%s!%s[%d:%d]\n", pgEmbedded.GetName(), wksTest.GetPage().GetName(),
wks.GetName(), wks.Columns(nCol).GetName(), nRow+1, nRow+1);
}
}
}
}
}
Check Graph Page if Embedded
PageBase::GetEmbeddingInfo also can used to check if page is embedded by return value like below.
void page_is_embedded(string strGraph)
{
GraphPage gp(strGraph);
if( !gp )
{
out_str(strGraph + " is not a valid graph");
return;
}
if( gp.GetEmbeddingInfo() ) // TRUE if the object is embedded in a Datasheet, otherwise FALSE.
{
out_str(strGraph + " is embedded graph");
}
else
{
out_str(strGraph + " is NOT embedded graph");
}
}
Sparklines
// example to show how to create/update sparklines on all
// columns on the current worksheet with alternating blue/red colors
void sparkline_colors()
{
DWORD dwCntrl = EMBEDGRAPH_IN_LABELS | EMBEDGRAPH_HIDE_AXES | EMBEDGRAPH_HIDE_LEGENDS
| EMBEDGRAPH_HIDE_SPECTRUMS | EMBEDGRAPH_HIDE_TEXT_OBJS | EMBEDGRAPH_SPARKLINE;
Worksheet wks = Project.ActiveLayer();
if(!wks)
return;
//add this will require theme_utils.c to be added to workspace
//int nRowHeight = 20
//wks_set_col_label_heights(wks, RCLT_SPARKLINE, nRowHeight, false);
waitCursor hrGlass;
for(int nC = 0; nC < wks.GetNumCols(); nC++)
{
if(wks.Columns(nC).GetType() != OKDATAOBJ_DESIGNATION_Y || is_col_all_text(wks, nC) > 0)
continue;
GraphPage gp;
DataPlot dp = plot_col(wks, nC, gp, IDM_PLOT_LINE, true, "sparkline_label", true, 0);
int ncolor = nC%2? SYSCOLOR_BLUE:SYSCOLOR_RED;
dp.SetColor(ncolor);
wks.EmbedGraph(RCLT_SPARKLINE, nC, gp, dwCntrl);
}
}
|