3.9.6.2 Creating Reports in Flat Sheet

Version Info

Minimum Origin Version Required: Origin 8 SR0

Examples

Reports vector numeric data and text via Datasheet::SetReportTree function in Worksheet class from tree to flat sheet.

void Datasheet_SetReportTree()
{
	int nID = 100; // Each node must have node ID and node ID must be unique	
	int nTableFormat = GETNBRANCH_FIT_COL_WIDTH | GETNBRANCH_FIT_ROW_HEIGHT;

	// 1. Create report tree
	Tree tr;
	tr.Report.ID = nID++; 
	tr.Report.SetAttribute(STR_LABEL_ATTRIB, "Dest Stats Report"); //Table title
	// TREE_Table attribute is critical in getting the report to work so must be present in every table level. 
	// Can set this attribute as 0 without any format, but many bits GETNBRANCH_* defined in oc_const.h to set table display format.
	tr.Report.SetAttribute(TREE_Table, nTableFormat);
	
	
	// 2. Prepare the table and show values got from vectors
	tr.Report.Table.ID = nID++;
	TreeNode trTable = tr.Report.Table;
	trTable.SetAttribute(STR_LABEL_ATTRIB, "Extreme Values"); //Table tile
	trTable.SetAttribute(TREE_Table, nTableFormat | GETNBRANCH_TRANSPOSE); 
	
	// setup column 1
	trTable.C1.ID = nID++;
	trTable.C1.SetAttribute(STR_LABEL_ATTRIB, "Description"); // Column label
	trTable.C1.SetAttribute(STR_COL_DESIGNATION_ATTRIB, OKDATAOBJ_DESIGNATION_NONE); // Set column type to None
	
	// setup column 2
	trTable.C2.ID = nID++;
	trTable.C2.SetAttribute(STR_LABEL_ATTRIB, "Max Values"); // Column label
	trTable.C2.SetAttribute(STR_COL_DESIGNATION_ATTRIB, OKDATAOBJ_DESIGNATION_Y); // Set column type to Y
	
	// setup column 3
	trTable.C3.ID = nID++;
	trTable.C3.SetAttribute(STR_LABEL_ATTRIB, "Min Values"); // Column label	
	trTable.C3.SetAttribute(STR_COL_DESIGNATION_ATTRIB, OKDATAOBJ_DESIGNATION_Y); // Set column type to Y
	
	
	// Put data from vector to table columns
	vector<string> vsDesc = {"Data1", "Data2", "Data3", "Data4", "Data5"};
	vector vMaxDatas = {100, 98, 95, 92, 84};
	vector vMinDatas = {5, 9, 13, 18, 21};
	trTable.C1.strVals = vsDesc;	
	trTable.C2.dVals = vMaxDatas; 
	trTable.C3.dVals = vMinDatas;	
	
	
	// 4. Prepare worksheet window to report
	WorksheetPage wksPage;
	wksPage.Create();	
	
	
	string	strSheetName = "Report Sheet";
	int nn = wksPage.AddLayer(strSheetName);
	if( nn < 0 )	
		return;	
	
	Worksheet wksOut = wksPage.Layers(nn);
	wksPage.Layers(0).Delete();	//delete the first default layer	
	
	
	// 5. Do report
	if( wksOut.SetReportTree(tr.Report) < 0 ) // Returns last row number on successful exit and -1 on failure.
	{
		printf("Fail to set report tree.\n");
		return;
	}		
	wksOut.AutoSize();	
}