Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 7 Jahren
Letzter Beitrag:
vor 6 Jahren, 12 Monaten
Beteiligte Autoren:
Arie, DerekT, Allard

print report based on table control

Startbeitrag von Arie am 18.07.2011 11:19

I have a report based on a table control.
The users can show/hide columns of the tablecontrol, using the build in AAF menu. No need to write any code.
But when printing a report based on the table, the column information is not taken into account.

Is there an option for this or do I have to add some code myself to this report(s)?



This appears to be missing from the WD arsenal - pity it would be very useful.
I looked for this myself some time ago without success.

iirc I had to add additional code to the report using the column..visible property to determine if the column should be printed or not.
The hardest part was getting the printed output to look anywhere near decent.



von DerekT - am 18.07.2011 11:35
how did you manage too "look it decent"?
Indeed, when hiding a column of the report-table, the other columns do not glue together automatically.
Do you have some sample code for that?

von Arie - am 18.07.2011 11:52
I will have a look and see if I can find the report.

Again from memory I seem to remember that I ended up having to write a procedure that interrogated the table and then resized and positioned the required columns for the report output.
I also had a 'spare' column to use as a fill for the right hand side if the columns selected by the user did not fill the width of the report.

The calcs required will depend on what you have as a starting point and of course how much you allow for modification (removal) of the table columns.
I need to go down this route as I was also required to allow the users to move columns.



von DerekT - am 18.07.2011 13:04
I cannot find the complete code but I have located some of my test code which should give you an idea of what I did.
It is going to depend pretty much on the size of you Table and\or report and what you functionality you allow the users (Hide\Move the columns).

For the test below I had a table with 6 columns and a basic report automatically generated by WD (Report on table button)
I did have more for manipulating the size and position of the columns to pront but cannot locate this at the moment.

If you need more let me know.



laVisColumn is an array of 0 by 2 string
lnColumnX is int //X pos of column in block
lrRptWidth_A is real //Total width of all report controls
lrRptWidth_B is real //Total width of all report controls to display
lsColumnName is string
lsColumnTitle is string

//Column start
lnColumnX = Column1_LIB..X //Set as first column in block
//Process hidden columns
FOR i = 1 TO 6 //Where 6 = total number of table columns
//Calculate the total width of all the report controls before removal
lrRptWidth_A += {"Column"+i,indControl}..Width
//Process for visible columns
IF {"wTestDT.tblTest.Column"+i,indControl}..Visible = True THEN
//Store the column titles and control names that are visible
//Calculate the total width of all the report controls used
lrRptWidth_B += {"Column"+i,indControl}..Width
//Remove hidden table columns from the report
{"Column"+i+"_LIB",indControl}..Visible = {"wTestDT.tblTest.Column"+i,indControl}..Visible
{"Column"+i,indControl}..Visible = {"wTestDT.tblTest.Column"+i,indControl}..Visible

//==== THIS PART I CANNOT FIND =====================================================================
//If lrRptWidth_B < lrRptWidth_A then decide whether to increase the width of the report columns
//or add (make visible) a dummy column title to the right of the report
//If lrRptWidth_B > lrRptWidth_A then decide whether to decrease the width of the report columns
// equally or according the the table display (rule of thumb 1mm = 24 pixels)

//Process only if columns have been hidden in the table
IF ArrayCount(laVisColumn) < 6 THEN
//Reposition visible columns
FOR j = 1 _TO_ ArrayCount(laVisColumn)
lsColumnTitle = laVisColumn[j][1] //Extract column title from the array
lsColumnName = laVisColumn[j][2] //Extract the control name from the array
{lsColumnTitle,indControl}..X = lnColumnX
{lsColumnName,indControl}..X = lnColumnX
//Increment the X pos for the next control by the width of the current control
lnColumnX += {lsColumnName,indControl}..Width

von DerekT - am 18.07.2011 18:00
Thanks Derek,
this is what I need. I will give it a try.
I also got an example from Paolo O., which is more generic already.
It uses a report-template with a header and some layout.
But without any columns and generates them on-the-fly.

von Arie - am 18.07.2011 18:10
So with the help of Derek and Paulo I wrote a little function, which fits my needs.
Here it is for any of you .

// Use this piece of code for a report based on a table-control
// It hides the columns which are made invisible by the end-user (using AAF right click)
// Assumptions:
// 1. columns of the tablecontrol and report must have the same name
// 2. a tablecontrol just has columns - a report has a static for the columntitle and an edit-field for the value
// Therefore columns of the table must start with ITEM_ (valuefield) and CAP_ (titlefield)
// i.e. table.Customername -> report.CAP_Customername and report.ITEM_Customername
// 3. the table control can hold a dummy column, which must have 'dummy' in the name
// this column and all remaining columns will be skipped in this report-alignment-handler.
// 4. the report-table must be centered. left/right justified is not supported yet.
PROCEDURE ReportAlignColumns(sReport is string)

sTable is string = {sReport,indReport}..SourceName
sCol is string
garrColumns is array of string
gnTotal is int = TableCount(sTable,toColumn)
FOR i = 1 _TO_ gnTotal
sCol = TableEnumColumn(sTable,i)
// stoppen bij de dummy-kolom - alles kolommen daarna doen ook niet meer
IF Position(sCol,"dummy",1,IgnoreCase) > 0 THEN
gnCount is int = ArrayCount(garrColumns)
nCol is int = 0
gnOffsetLeft is currency
gnOffsetRight is currency
FOR EACH s OF garrColumns
gnOffsetLeft = 0
gnOffsetRight = 0
IF NOT {sTable+"."+s,indControl}..Visible THEN
{"ITEM_"+s,indControl}..Visible = False
{"CAP_"+s,indControl}..Visible = False
gnOffsetLeft = {"ITEM_"+s,indControl}..Width / 2
gnOffsetRight = {"ITEM_"+s,indControl}..Width - gnOffsetLeft
IF gnOffsetLeft 0 THEN
FOR i = 1 _TO_ nCol-1
{"ITEM_"+garrColumns,indControl}..X += gnOffsetLeft
{"CAP_"+garrColumns,indControl}..X += gnOffsetLeft
IF gnOffsetRight 0 THEN
FOR i = nCol+1 _TO_ gnCount
{"ITEM_"+garrColumns,indControl}..X -= gnOffsetRight
{"CAP_"+garrColumns,indControl}..X -= gnOffsetRight

von Arie - am 19.07.2011 07:14
what you want is possible without any coding!

I have a table and a report based on the table. If I remove colums then the print doesnot show them eighter.

Absolutely no coding needed.

How did I do it
I gave the option to print via the AAF feastures. I didnot create a report!. When selecting to print and all colums are still availeble than and autogenerated windev screen asks if you want to print landscape or not. If I remove colums till there are 3 left and kit print the report is automaticly created with onley the 3 colums.


von Allard - am 24.07.2011 17:30
Hi Allard,
that's a nice one. Still learning.

However this report isn't good enough for me. I want a specific layout, which I use for all reports. ie including the company name.


von Arie - am 24.07.2011 19:38
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.