The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Dynamic Report Table

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Fry Posted - 08/23/2016 : 06:29:05 AM
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:

Hello Origin community,

I’m trying to setup a simple report with one table (like mentioned in the help file).
Is it possible to create the “rows”(red marked in the code below) dynamically like in a for-loop? Because I don’t know the number of rows jet.
I’d tried to use a macro but it didn’t work for me.


// 5. Add the second row to this table
tr.Report.Table.R2.ID = nID++;
tr.Report.Table.R2.SetAttribute(STR_LABEL_ATTRIB, "Row 2"); //Row label

// 6. Fill in values for the two cells in the second row
tr.Report.Table.R2.C1.ID = nColIDBase + 1;
tr.Report.Table.R2.C1.dVal = 15;
...

Thank you for the support!
René
2   L A T E S T    R E P L I E S    (Newest First)
Fry Posted - 08/25/2016 : 07:16:08 AM
Hi Yuki,

thank you for the fast support! I'll try it in the next days. I think your approch will work fine for me, I just overlooked this way/option.

Thanks!
yuki_wu Posted - 08/24/2016 : 06:14:48 AM
Hi René,

I changed the example in in the help file, which you can refer to:

void Datasheet_SetReportTree_Ex1_new(bool bTransposeTable = false)
{
	int nID = 1000;
	int nTableFormat = GETNBRANCH_OPEN | GETNBRANCH_HIDE_COL_HEADINGS| GETNBRANCH_HIDE_ROW_HEADINGS | GETNBRANCH_FIT_COL_WIDTH | GETNBRANCH_FIT_ROW_HEIGHT;
	// 1. Create report tree
	Tree tr;
	tr.Report.ID = nID++;
	tr.Report.SetAttribute(STR_LABEL_ATTRIB, "Sample Report Tree"); //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. Create report table
	tr.Report.Table.ID = nID++;
	tr.Report.Table.SetAttribute(STR_LABEL_ATTRIB, "This is a simple table"); // Table title. If not set this, will show as empty here
	int nSubTableFormat = nTableFormat;
	if(bTransposeTable)
		nSubTableFormat |= GETNBRANCH_TRANSPOSE; // transpose this table
	tr.Report.Table.SetAttribute(TREE_Table, nSubTableFormat); 
	
	//3. add rows and columns to this table
	int nRows = 8;
	int iRow = 0;
	
	while(iRow++ < nRows)
	{
		string strRx = "Row" + iRow;
		string strLabel = "Row " + iRow;
		TreeNode trRx = tr.Report.Table.AddNode(strRx);
		trRx.ID = nID++;
		trRx.SetAttribute(STR_LABEL_ATTRIB, strLabel);
		
		//col
		int nCols = 2;
		int iCol = 0;
		int nColID = 3210;
		while(iCol++ < nCols)
		{
			string strCx = "Col" + iCol;
			TreeNode trCx = trRx.AddNode(strCx);
			trCx.ID= nColID++;
			trCx.dVal = 15;
			
		}
	}
	
	
	//7. Prepare worksheet window to report
	WorksheetPage wksPage;
	wksPage.Create();	
 
	DWORD 	dwOptions = WP_SHEET_HIERARCHY | CREATE_NO_DEFAULT_TEMPLATE;		
	string	strSheetName = "Report Sheet";
	int nn = wksPage.AddLayer(strSheetName, dwOptions);
	if( nn < 0 )	
		return;	
 
	Worksheet wksOut = wksPage.Layers(nn);
	wksPage.Layers(0).Delete();	//delete the first default layer	
 
	// 8. 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();
	//out_tree(tr);
}


Hope it helps!

Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000