2.2.3.11.2 ReportBase::CreateTableWithMatrix
Description
Create report table with matrix data
Syntax
CreateTableWithMatrix( LPCSTR lpcszTagName, LPCSTR lpcszLabel, int nId, const matrix & mm, const vector<string> & saColNames, const vector<string> & saRowNames)
Parameters
- lpcszTagName
- [input] table tag name
- lpcszLabel
- [input] table title
- nId
- [input] table id
- mm
- [input] value to fill in the table
- saColNames
- [input] column names
- saRowNames
- [input] row names
Return
the newly created table
Examples
EX1
#include <ReportTree.h>
enum{
RTID_TABLE1 = 10,
RTID_TABLE2 = 20,
RTID_TABLE3 = 30,
};
void test_CreateTableWithMatrix()
{
Worksheet wks = Project.ActiveLayer();
WorksheetPage wp = wks.GetPage();
int nn = wp.AddLayer("Report1");
Worksheet wksRt = wp.Layers(nn);
Tree trReportTree;
ReportTree rt(trReportTree);
ReportTable rtF = rt.CreateTable("factor", "AddRow Example", RTID_TABLE1);
if(rtF)
{
StringArray sa = {"Fixed", "15", "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"};
StringArray saLabel = { "Type", "Levels","Values"};
StringArray saColTag = {"","",""};
string strRowHeader = "Factor 1";
TreeNode trFactor = rtF.AddRow("factor"+1, sa, strRowHeader, saLabel, saColTag, RTID_TABLE1+1 );
if (trFactor)
{
//for version <= Origin 2025 if comma is decimal separator,
//you can make the cell always text to avoid "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" being considered missing value
string str = TNVAL_TYPE_CSTRING;
tree_set_attribute_to_all_nodes(trFactor, STR_TYPE_ATTRIB, str, true);
}
}
int id = RTID_TABLE2;
ReportTable rtData = rt.CreateTable("data"+(int)id, "AddColumn Example", id);
if(rtData)
{
vector<string> vs = {"A", "B", "C"};
rtData.AddColumn(vs, "xfactor", id+1, "PlotIntoLayer", OKDATAOBJ_DESIGNATION_X);
vector vv = {0.12, 0.34, 0.56};
rtData.AddColumn(vv, "yfactor", id+2, "PlotIntoLayer", OKDATAOBJ_DESIGNATION_Y);
rtData.AddColumn(vv*5, "yfactor2", id+3, "PlotIntoLayer", OKDATAOBJ_DESIGNATION_Y);
}
id = RTID_TABLE3;
matrix mDoublesByDefault = {{1.1,2.2,3.3},{4.4,5.5,6.6}};
vector<string> saColNames = {"A", "B", "C"}, saRowNames = {"1", "2"};
ReportTable rtMData = rt.CreateTableWithMatrix("data"+(int)id, "Matrix example", id, mDoublesByDefault, saColNames, saRowNames);
rt.GenerateReport(wksRt, true);
wksRt.AutoSize();
}
Remark
See Also
ReportBase's examples
Header to Included
ReportTree.h
|