ReportBase

 

Contents

Name

ReportBase

Remark

Hierarchy

Examples

Active a worksheet and run "report_ex"

#include <Origin.h>
#include <ReportTree.h>
#include <..\Originlab\theme_utils.h>

enum{
        RTID_TABLE1 = 10,
        RTID_TABLE2 = 20,
        RTID_TABLE3 = 30,
        RTID_TABLE4 = 40,
        RTID_TABLE5 = 50,
};

enum{
        RDID_DATA1 = 10,
};

ReportTable ReportTable_AddColumn_ex(ReportBase& table, const int id)
{
        ReportTable rtData = table.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);
        }
        
        return rtData;
}

void ReportTable_AddRow_ex(ReportBase& table, const int id)
{
        ReportTable rt = table.CreateTable("table"+(int)id, "AddRow Example 1", id);      
        if(rt)
        {
                rt.AddRow("row1", "AddRow", "This is AddRow", id+1);
                rt.AddRow("row2", "AddRow", 12345.6789, id+2);
                format_report_table(rt, true);           
        }
}

void ReportTable_AddRow_ex2(ReportBase& table, const int id)
{
        ReportTable rt = table.CreateTable("table"+(int)id, "AddRow Example 2", id);      
        if(rt)
        {
                vector<string> vsLabel = {"A test", "B test", "C test"};
                vector vv = {0.12, 0.34, 0.56};
                rt.AddRow("row1", vv, "Factor A(Light)", vsLabel, NULL, id+1, "Factor B(100mg)");
                rt.AddRow("row2", vv+5, "Factor A(Light)", vsLabel, NULL, id+2, "Factor B(200mg)");
                rt.AddRow("row3", vv*0.5, "Factor A(Moderate)", vsLabel, NULL, id+3, "Factor B(100mg)");
                rt.AddRow("row4", vv*10, "Factor A(Moderate)", vsLabel, NULL, id+4, "Factor B(200mg)");
        }
}

void ReportData_PlotIntoLayer_ex(ReportBase& table, const int id, const ReportData& rd, const int rdid)
{
        ReportTable rtGraph = table.CreateTable("graph"+(int)id, "SetCell Example", id, -1, 1);    
        if(rtGraph)
        {
                GraphPage gp;
                gp.Create("origin", CREATE_HIDDEN);
                rtGraph.SetCell(0, 0, gp, EMBEDGRAPH_MOVE_IF_ALREADY_EMBEDDED);
                rtGraph.SetCell(-1, 0, "World");
                rd.PlotIntoLayer(gp.Layers(0), rdid, NULL);
        }
}

void ReportData_GetDataRange_ex(ReportBase& table, const int id, const ReportData& rd, const int nTableID)
{
        GraphPage gp;
        gp.Create("origin", CREATE_HIDDEN);
        
        ReportTable rtPlot = table.CreateTable("graph"+(int)id, "GetDataRange Example", id);
        rtPlot.SetCell(0, 0, gp, EMBEDGRAPH_MOVE_IF_ALREADY_EMBEDDED);
        
        TreeNode trTable = tree_get_node_by_id(rd, nTableID, true);
        if(trTable)
        {
                int nYCount = trTable.GetNodeCount() - 1;//one X
                vector<int> nYID;
                nYID.Data(nTableID+1, nTableID+nYCount);
                
                DataRange drData;
                if( rd.GetDataRange(drData, nTableID, nTableID+1, nYID, nYCount, TRUE, FALSE, TRUE) )
                {     
                        GraphLayer gl = gp.Layers(0);
                        gl.AddPlot(drData);
                        gl.Rescale();
                }
        }
}

void ReportData_GetWorksheet_ex(ReportData& rdData)
{
        if(!rdData){ return; }
        Worksheet wksReport;
        rdData.GetWorksheet(wksReport);
        if(!wksReport)
                return;
        wksReport.AutoSize();
}

void report_ex()
{
        Worksheet wksActive = Project.ActiveLayer();
        if(!wksActive)
        {
                out_str("No active worksheet");
                return;
        }
        
        WorksheetPage wp = wksActive.GetPage();
        int nn = wp.AddLayer("Report1");        
        if(nn < 0)
        {
                out_str("Fail to create report sheet");
                return;
        }     
        Worksheet wksRt = wp.Layers(nn);
        
        nn = wp.AddLayer("Report Data1");    
        if(nn < 0)
        {
                out_str("Fail to create data sheet");
                return;
        }     
        Worksheet wksRd = wp.Layers(nn);
        
        Tree trReportData, trReportTree;
        ReportTree rt(trReportTree);
        ReportData rd(trReportData);
        
        rd.SetWorksheet(wksRd);  
        ReportTable_AddColumn_ex(rd, RDID_DATA1);
        
        ReportTable rt1 = ReportTable_AddColumn_ex(rt, RTID_TABLE1);
        if(rt1)
                format_report_table(rt1, true);          
        
        ReportTable_AddRow_ex(rt, RTID_TABLE2);               
        ReportTable_AddRow_ex2(rt, RTID_TABLE3);
        
        ReportData_PlotIntoLayer_ex(rt, RTID_TABLE4, rd, RDID_DATA1);
        
        ReportData_GetDataRange_ex(rt, RTID_TABLE5, rd, RDID_DATA1);
        
        rt.GenerateReport(wksRt, true);     
        wksRt.AutoSize();
        
        ReportData_GetWorksheet_ex(rd);
}

header to Include

ReportTree.h

Reference

Members

Name Brief Example
CreateTable Create one table for the report
ReportBase Constructor