Hello everyone,
I have a script where I am trying to get the format of a column and then apply that to a textbox that is in a table box.
I tried using this col_for=col<< Get Format; but I can't use what it returns in this loop
For Each({col_name}, column_names,
col = Column(dty, col_name);
col_for=(col<< Get Format);
insertinto(col_format_text,col_for);
insertinto(col_width,col<< Get Display Width);
insertinto(col_wrap,col << Get Display Width);
);
I get an error when I try and add the col_for into the list.
The reason I am doing this is that I am later trying to use the list to set the textbox format later with this:
for(j=1, j<=n items(column_names), j++,
For(i=1,i<= qty_of_rows, i++,
col_list[j] << append(Text Box(col_var_list[j][i]),<<set format(col_format[j]),<<set width(col_width[j]), << set wrap (col_width[j]));
);
);
);
tb << Set Shade Alternate Rows( 1 );
tb << Set Row Borders( 1 );
tb << Set Row Borders( 1 );
tb << Set Column Borders( 1 );
The full script I am working on is this and the intent is to be able to easily save a data table to a PDF for printing. This would grab the formatting of the data table and apply it to the table box columns:
dty=current data table();
createdate=today();
column_names=dty<<get column names("string");
qty_of_rows=N Rows(dty);
col_var_list={};
var_list={};
col_list={};
col_format={};
col_format_text={};
col_width={};
col_wrap={};
col_for={};
col_for2={};
// Loop through each column name
For Each({col_name}, column_names,
col = Column(dty, col_name);
col_for=(col<< Get Format);
insertinto(col_format_text,col_for);
insertinto(col_width,col<< Get Display Width);
insertinto(col_wrap,col << Get Display Width);
);
//old way that was not dynamic, had to set up each line
/*
qnval=dty:"QN Number"n << Get Values;
coval = dty:"Created On"n << Get Values;
wonval = dty:"Workorder"n << Get Values;
opval = dty:"Dept"n << Get Values;
ccval = dty:"Cause Category"n << Get Values;
dovval = dty:"Description of Variation"n << Get Values;
vcval = dty:"Variation Comment"n << Get Values;
sval = dty:"Severity"n << Get Values;
*/
for(i=1, i<=n items(column_names), i++,
col_var_list[i]=column(dty,column_names[i])<< Get Values;;
);
//old way that was not dynamic, had to set up each line
/*
nw = New Window( "PDF Print of PVNs",<<window view("invisible"),
tb = Table Box(
col1 = Col Box( "QN Number" ),
col2 = Col Box( "Created On"),
col3 = Col Box( "Workorder"),
col4 = Col Box( "Dept"),
col5 = Col Box( "Severity"),
col6 = Col Box( "Description of Variation"),
col7 = Col Box( "Narrative Cause"),
col8 = Col Box( "Variation Comment")
)
);
*/
nw = New Window( "PDF Print of PVNs",
tb = Table Box()
);
for(i=1, i<=n items(column_names), i++,
tb << append( col_list[i]=col Box(column_names[i]));
);
//old way that was not dynamic, had to set up each line
/*
For Each ({value, i}, qnval,
col1 << append( Text Box(qnval[i]));
col2 << append( Text Box(Format(coval[i],"Format Pattern", "<YYYY></><MM></><DD> <hh24><:><mm>"),<<set width(100)));
col3 << append( Text Box(wonval[i]));
col4 << append( Text Box(opval[i]));
col5 << append( Text Box(sval[i]));
col6 << append( Text Box(ccval [i], << set wrap (150)));
col7 << append( Text Box(dovval[i], << set wrap (325)));
col8 << append( Text Box(vcval[i], << set wrap (325)));
);
*/
for(j=1, j<=n items(column_names), j++,
For(i=1,i<= qty_of_rows, i++,
col_list[j] << append(Text Box(col_var_list[j][i]),<<set format(col_format[j]),<<set width(col_width[j]), << set wrap (col_wrap[j]));
);
);
);
tb << Set Shade Alternate Rows( 1 );
tb << Set Row Borders( 1 );
tb << Set Row Borders( 1 );
tb << Set Column Borders( 1 );
wajrn = Window( "example file" );
wajrn << journal;
wajrn=Current Journal();
wajrn << Show Window( 0 );
wajrn <<Set page setup(
margins( .1, .1, .1, .1 ),
scale( .8 ),
portrait( 0 ),
paper size( "Letter" )
);
wajrn << Set Print Headers(""/*left*/, ""/*center*/,""/*right*/);
wajrn << Set Print Footers(""/*left*/, ""/*center*/,"Updated on " || char(MDYHMS(createdate)));
//wajrn <<Save PDF("Put in file location here");
wajrn<<close window;
nw<<close window;
I attached a table that I have been working with along with this script.
Thanks for any help!
Steve